mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 11:14:12 +02:00
Add the following new hooks to $templates, $fields and $fieldgroups: renameReady($item, $oldName, $newName); renamed($item, $oldName, $newName); Added the following new hooks to $fieldgroups: fieldAdded($fieldgroup, $field); fieldRemoved($fieldgroup, $field); Make template selectable for Page fields in InputfieldSelector, plus other minor updates.
This commit is contained in:
@@ -7,13 +7,17 @@
|
|||||||
* #pw-body For full details on all methods available in a Fieldgroup, be sure to also see the `WireArray` class.
|
* #pw-body For full details on all methods available in a Fieldgroup, be sure to also see the `WireArray` class.
|
||||||
* #pw-var $fieldgroups
|
* #pw-var $fieldgroups
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @method int saveContext(Fieldgroup $fieldgroup)
|
* @method int saveContext(Fieldgroup $fieldgroup)
|
||||||
* @method array getExportData(Fieldgroup $fieldgroup)
|
* @method array getExportData(Fieldgroup $fieldgroup)
|
||||||
* @method array setImportData(Fieldgroup $fieldgroup, array $data)
|
* @method array setImportData(Fieldgroup $fieldgroup, array $data)
|
||||||
*
|
*
|
||||||
|
* @method void fieldRemoved(Fieldgroup $fieldgroup, Field $field)
|
||||||
|
* @method void fieldAdded(Fieldgroup $fieldgroup, Field $field)
|
||||||
|
* @method void sorted(Fieldgroup $fieldgroup, array $oldOrder, array $newOrder)
|
||||||
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -27,6 +31,10 @@ class Fieldgroups extends WireSaveableItemsLookup {
|
|||||||
*/
|
*/
|
||||||
protected $fieldgroupsArray;
|
protected $fieldgroupsArray;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function init() {
|
public function init() {
|
||||||
$this->fieldgroupsArray = $this->wire(new FieldgroupsArray());
|
$this->fieldgroupsArray = $this->wire(new FieldgroupsArray());
|
||||||
$this->load($this->fieldgroupsArray);
|
$this->load($this->fieldgroupsArray);
|
||||||
@@ -142,54 +150,80 @@ class Fieldgroups extends WireSaveableItemsLookup {
|
|||||||
*/
|
*/
|
||||||
public function ___save(Saveable $item) {
|
public function ___save(Saveable $item) {
|
||||||
|
|
||||||
$database = $this->wire('database');
|
$database = $this->wire()->database;
|
||||||
|
|
||||||
/** @var Fieldgroup $item */
|
/** @var Fieldgroup $fieldgroup */
|
||||||
|
$fieldgroup = $item;
|
||||||
|
$datas = array();
|
||||||
|
$fieldsAdded = array();
|
||||||
|
$fieldsRemoved = array();
|
||||||
|
|
||||||
if($item->id && $item->removedFields) {
|
if($fieldgroup->id && $fieldgroup->removedFields) {
|
||||||
|
|
||||||
foreach($this->wire('templates') as $template) {
|
foreach($this->wire()->templates as $template) {
|
||||||
if($template->fieldgroup->id !== $item->id) continue;
|
if($template->fieldgroup->id !== $fieldgroup->id) continue;
|
||||||
foreach($item->removedFields as $field) {
|
foreach($fieldgroup->removedFields as $field) {
|
||||||
// make sure the field is valid to delete from this template
|
// make sure the field is valid to delete from this template
|
||||||
$error = $this->isFieldNotRemoveable($field, $item, $template);
|
$error = $this->isFieldNotRemoveable($field, $fieldgroup, $template);
|
||||||
if($error !== false) throw new WireException("$error Save of fieldgroup changes aborted.");
|
if($error !== false) throw new WireException("$error Save of fieldgroup changes aborted.");
|
||||||
if($field->type) $field->type->deleteTemplateField($template, $field);
|
if($field->type) $field->type->deleteTemplateField($template, $field);
|
||||||
$item->finishRemove($field);
|
$fieldgroup->finishRemove($field);
|
||||||
|
$fieldsRemoved[] = $field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->resetRemovedFields();
|
$fieldgroup->resetRemovedFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
$contextData = array();
|
if($fieldgroup->id) {
|
||||||
if($item->id) {
|
// load context data to populate back after fieldgroup save
|
||||||
// save context data
|
$sql = 'SELECT fields_id, data FROM fieldgroups_fields WHERE fieldgroups_id=:fieldgroups_id';
|
||||||
$query = $database->prepare("SELECT fields_id, data FROM fieldgroups_fields WHERE fieldgroups_id=:item_id");
|
$query = $database->prepare($sql);
|
||||||
$query->bindValue(":item_id", (int) $item->id, \PDO::PARAM_INT);
|
$query->bindValue(':fieldgroups_id', (int) $fieldgroup->id, \PDO::PARAM_INT);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
/** @noinspection PhpAssignmentInConditionInspection */
|
/** @noinspection PhpAssignmentInConditionInspection */
|
||||||
while($row = $query->fetch(\PDO::FETCH_ASSOC)) {
|
while($row = $query->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
$contextData[$row['fields_id']] = $row['data'];
|
$fields_id = (int) $row['fields_id'];
|
||||||
|
$datas[$fields_id] = $row['data'];
|
||||||
}
|
}
|
||||||
$query->closeCursor();
|
$query->closeCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = parent::___save($item);
|
$result = parent::___save($fieldgroup);
|
||||||
|
|
||||||
if(count($contextData)) {
|
// identify any fields added
|
||||||
|
foreach($fieldgroup as $field) {
|
||||||
|
if(!array_key_exists($field->id, $datas)) {
|
||||||
|
$fieldsAdded[] = $field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($datas)) {
|
||||||
// restore context data
|
// restore context data
|
||||||
foreach($contextData as $fields_id => $data) {
|
$fieldgroups_id = (int) $fieldgroup->id;
|
||||||
$fieldgroups_id = (int) $item->id;
|
foreach($datas as $fields_id => $data) {
|
||||||
$fields_id = (int) $fields_id;
|
$sql = "UPDATE fieldgroups_fields SET data=:data WHERE fieldgroups_id=:fieldgroups_id AND fields_id=:fields_id";
|
||||||
$query = $database->prepare("UPDATE fieldgroups_fields SET data=:data WHERE fieldgroups_id=:fieldgroups_id AND fields_id=:fields_id"); // QA
|
$query = $database->prepare($sql);
|
||||||
|
if($data === null) {
|
||||||
|
$query->bindValue(":data", null, \PDO::PARAM_NULL);
|
||||||
|
} else {
|
||||||
$query->bindValue(":data", $data, \PDO::PARAM_STR);
|
$query->bindValue(":data", $data, \PDO::PARAM_STR);
|
||||||
|
}
|
||||||
$query->bindValue(":fieldgroups_id", $fieldgroups_id, \PDO::PARAM_INT);
|
$query->bindValue(":fieldgroups_id", $fieldgroups_id, \PDO::PARAM_INT);
|
||||||
$query->bindValue(":fields_id", $fields_id, \PDO::PARAM_INT);
|
$query->bindValue(":fields_id", $fields_id, \PDO::PARAM_INT);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trigger any fields added
|
||||||
|
foreach($fieldsAdded as $field) {
|
||||||
|
$this->fieldAdded($fieldgroup, $field);
|
||||||
|
}
|
||||||
|
// trigger any fieldsl removed
|
||||||
|
foreach($fieldsRemoved as $field) {
|
||||||
|
$this->fieldRemoved($fieldgroup, $field);
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +304,7 @@ class Fieldgroups extends WireSaveableItemsLookup {
|
|||||||
foreach($contexts as $fieldID => $context) {
|
foreach($contexts as $fieldID => $context) {
|
||||||
$field = $fieldgroup->getFieldContext((int) $fieldID);
|
$field = $fieldgroup->getFieldContext((int) $fieldID);
|
||||||
if(!$field) continue;
|
if(!$field) continue;
|
||||||
if($this->wire('fields')->saveFieldgroupContext($field, $fieldgroup)) $numSaved++;
|
if($this->wire()->fields->saveFieldgroupContext($field, $fieldgroup)) $numSaved++;
|
||||||
}
|
}
|
||||||
return $numSaved;
|
return $numSaved;
|
||||||
}
|
}
|
||||||
@@ -486,5 +520,28 @@ class Fieldgroups extends WireSaveableItemsLookup {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook called when field has been added to fieldgroup
|
||||||
|
*
|
||||||
|
* #pw-hooker
|
||||||
|
*
|
||||||
|
* @param Fieldgroup $fieldgroup
|
||||||
|
* @param Field $field
|
||||||
|
* @since 3.0.193
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function ___fieldAdded(Fieldgroup $fieldgroup, Field $field) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook called when field has been removed from fieldgroup
|
||||||
|
*
|
||||||
|
* #pw-hooker
|
||||||
|
*
|
||||||
|
* @param Fieldgroup $fieldgroup
|
||||||
|
* @param Field $field
|
||||||
|
* @since 3.0.193
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function ___fieldRemoved(Fieldgroup $fieldgroup, Field $field) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
* Wire Data Access Object, provides reusable capability for loading, saving, creating, deleting,
|
* Wire Data Access Object, provides reusable capability for loading, saving, creating, deleting,
|
||||||
* and finding items of descending class-defined types.
|
* and finding items of descending class-defined types.
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @method WireArray load(WireArray $items, $selectors = null)
|
* @method WireArray load(WireArray $items, $selectors = null)
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
* @method void added(Saveable $item) #pw-hooker
|
* @method void added(Saveable $item) #pw-hooker
|
||||||
* @method void deleted(Saveable $item) #pw-hooker
|
* @method void deleted(Saveable $item) #pw-hooker
|
||||||
* @method void cloned(Saveable $item, Saveable $copy) #pw-hooker
|
* @method void cloned(Saveable $item, Saveable $copy) #pw-hooker
|
||||||
|
* @method void renameReady(Saveable $item, $oldName, $newName)
|
||||||
|
* @method void renamed(Saveable $item, $oldName, $newName)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -256,6 +258,17 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate {
|
|||||||
$this->saveReady($item);
|
$this->saveReady($item);
|
||||||
$data = $item->getTableData();
|
$data = $item->getTableData();
|
||||||
$binds = array();
|
$binds = array();
|
||||||
|
$namePrevious = false;
|
||||||
|
|
||||||
|
if($id && $item->isChanged('name')) {
|
||||||
|
$query = $database->prepare("SELECT name FROM `$table` WHERE id=:id");
|
||||||
|
$query->bindValue(':id', $id, \PDO::PARAM_INT);
|
||||||
|
$query->execute();
|
||||||
|
$oldName = $query->fetchColumn();
|
||||||
|
$query->closeCursor();
|
||||||
|
if($oldName != $item->name) $namePrevious = $oldName;
|
||||||
|
if($namePrevious) $this->renameReady($item, $namePrevious, $item->name);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($data as $key => $value) {
|
foreach($data as $key => $value) {
|
||||||
if(!$this->saveItemKey($key)) continue;
|
if(!$this->saveItemKey($key)) continue;
|
||||||
@@ -292,6 +305,7 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($result) {
|
if($result) {
|
||||||
|
if($namePrevious) $this->renamed($item, $namePrevious, $item->name);
|
||||||
$this->saved($item);
|
$this->saved($item);
|
||||||
$this->resetTrackChanges();
|
$this->resetTrackChanges();
|
||||||
} else {
|
} else {
|
||||||
@@ -475,6 +489,16 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate {
|
|||||||
*/
|
*/
|
||||||
public function ___cloneReady(Saveable $item, Saveable $copy) { }
|
public function ___cloneReady(Saveable $item, Saveable $copy) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook that runs right before item is to be renamed.
|
||||||
|
*
|
||||||
|
* @param Saveable $item
|
||||||
|
* @param string $oldName
|
||||||
|
* @param string $newName
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function ___renameReady(Saveable $item, $oldName, $newName) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook that runs right after an item has been saved.
|
* Hook that runs right after an item has been saved.
|
||||||
*
|
*
|
||||||
@@ -517,8 +541,6 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate {
|
|||||||
/**
|
/**
|
||||||
* Hook that runs right after an item has been cloned.
|
* Hook that runs right after an item has been cloned.
|
||||||
*
|
*
|
||||||
* Unlike after(delete), it has already been confirmed that the item was indeed deleted.
|
|
||||||
*
|
|
||||||
* @param Saveable $item
|
* @param Saveable $item
|
||||||
* @param Saveable $copy
|
* @param Saveable $copy
|
||||||
*
|
*
|
||||||
@@ -527,6 +549,18 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate {
|
|||||||
$this->log("Cloned '$item->name' to '$copy->name'", $item);
|
$this->log("Cloned '$item->name' to '$copy->name'", $item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook that runs right after an item has been renamed.
|
||||||
|
*
|
||||||
|
* @param Saveable $item
|
||||||
|
* @param string $oldName
|
||||||
|
* @param string $newName
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function ___renamed(Saveable $item, $oldName, $newName) {
|
||||||
|
$this->log("Renamed $oldName to $newName", $item);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables use of $apivar('name') or wire()->apivar('name')
|
* Enables use of $apivar('name') or wire()->apivar('name')
|
||||||
*
|
*
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* Provides same functionality as WireSaveableItems except that this class includes joining/modification of a related lookup table
|
* Provides same functionality as WireSaveableItems except that this class includes joining/modification of a related lookup table
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -40,12 +40,13 @@ abstract class WireSaveableItemsLookup extends WireSaveableItems {
|
|||||||
*/
|
*/
|
||||||
protected function getLoadQuery($selectors = null) {
|
protected function getLoadQuery($selectors = null) {
|
||||||
$query = parent::getLoadQuery($selectors);
|
$query = parent::getLoadQuery($selectors);
|
||||||
$database = $this->wire('database');
|
$database = $this->wire()->database;
|
||||||
$table = $database->escapeTable($this->getTable());
|
$table = $database->escapeTable($this->getTable());
|
||||||
$lookupTable = $database->escapeTable($this->getLookupTable());
|
$lookupTable = $database->escapeTable($this->getLookupTable());
|
||||||
$lookupField = $database->escapeCol($this->getLookupField());
|
$lookupField = $database->escapeCol($this->getLookupField());
|
||||||
$query->select("$lookupTable.$lookupField"); // QA
|
$query->select("$lookupTable.$lookupField"); // QA
|
||||||
$query->leftjoin("$lookupTable ON $lookupTable.{$table}_id=$table.id ")->orderby("sort"); // QA
|
$query->leftjoin("$lookupTable ON $lookupTable.{$table}_id=$table.id ")->orderby("sort");
|
||||||
|
// $query->leftjoin("$lookupTable ON $lookupTable.{$table}_id=$table.id ")->orderby("$table.id, $lookupTable.sort");
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,8 +62,8 @@ abstract class WireSaveableItemsLookup extends WireSaveableItems {
|
|||||||
*/
|
*/
|
||||||
protected function ___load(WireArray $items, $selectors = null) {
|
protected function ___load(WireArray $items, $selectors = null) {
|
||||||
|
|
||||||
|
$database = $this->wire()->database;
|
||||||
$query = $this->getLoadQuery($selectors);
|
$query = $this->getLoadQuery($selectors);
|
||||||
$database = $this->wire('database');
|
|
||||||
$sql = $query->getQuery();
|
$sql = $query->getQuery();
|
||||||
$stmt = $database->prepare($sql);
|
$stmt = $database->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
@@ -70,6 +71,7 @@ abstract class WireSaveableItemsLookup extends WireSaveableItems {
|
|||||||
|
|
||||||
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
|
|
||||||
|
/** @var HasLookupItems $item */
|
||||||
$item = $this->makeBlankItem();
|
$item = $this->makeBlankItem();
|
||||||
$lookupValue = $row[$lookupField];
|
$lookupValue = $row[$lookupField];
|
||||||
unset($row[$lookupField]);
|
unset($row[$lookupField]);
|
||||||
@@ -93,6 +95,7 @@ abstract class WireSaveableItemsLookup extends WireSaveableItems {
|
|||||||
|
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
$items->setTrackChanges(true);
|
$items->setTrackChanges(true);
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +128,7 @@ abstract class WireSaveableItemsLookup extends WireSaveableItems {
|
|||||||
throw new WireException("$class::save() requires an item that implements HasLookupItems interface");
|
throw new WireException("$class::save() requires an item that implements HasLookupItems interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
$database = $this->wire('database');
|
$database = $this->wire()->database;
|
||||||
$lookupTable = $database->escapeTable($this->getLookupTable());
|
$lookupTable = $database->escapeTable($this->getLookupTable());
|
||||||
$lookupField = $database->escapeCol($this->getLookupField());
|
$lookupField = $database->escapeCol($this->getLookupField());
|
||||||
$table = $database->escapeTable($this->getTable());
|
$table = $database->escapeTable($this->getTable());
|
||||||
@@ -141,16 +144,19 @@ abstract class WireSaveableItemsLookup extends WireSaveableItems {
|
|||||||
$item_id = (int) $item->id; // reload, in case it was 0 before
|
$item_id = (int) $item->id; // reload, in case it was 0 before
|
||||||
|
|
||||||
$sort = 0;
|
$sort = 0;
|
||||||
if($item_id) foreach($item->getLookupItems() as $key => $value) {
|
if($item_id) {
|
||||||
|
$sql = "INSERT INTO $lookupTable SET {$table}_id=:item_id, $lookupField=:value_id, sort=:sort";
|
||||||
|
$query = $database->prepare($sql);
|
||||||
|
foreach($item->getLookupItems() as $key => $value) {
|
||||||
$value_id = (int) $value->id;
|
$value_id = (int) $value->id;
|
||||||
$query = $database->prepare("INSERT INTO $lookupTable SET {$table}_id=:item_id, $lookupField=:value_id, sort=:sort");
|
$query->bindValue(":item_id", $item_id, \PDO::PARAM_INT);
|
||||||
$query->bindValue(":item_id", $item_id);
|
$query->bindValue(":value_id", $value_id, \PDO::PARAM_INT);
|
||||||
$query->bindValue(":value_id", $value_id);
|
$query->bindValue(":sort", $sort, \PDO::PARAM_INT);
|
||||||
$query->bindValue(":sort", $sort);
|
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$this->resetTrackChanges();
|
|
||||||
$sort++;
|
$sort++;
|
||||||
}
|
}
|
||||||
|
$this->resetTrackChanges();
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -163,7 +169,7 @@ abstract class WireSaveableItemsLookup extends WireSaveableItems {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function ___delete(Saveable $item) {
|
public function ___delete(Saveable $item) {
|
||||||
$database = $this->wire('database');
|
$database = $this->wire()->database;
|
||||||
$lookupTable = $database->escapeTable($this->getLookupTable());
|
$lookupTable = $database->escapeTable($this->getLookupTable());
|
||||||
$table = $database->escapeTable($this->getTable());
|
$table = $database->escapeTable($this->getTable());
|
||||||
$item_id = (int) $item->id;
|
$item_id = (int) $item->id;
|
||||||
|
@@ -1055,7 +1055,7 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
|||||||
$value = date('Y-m-d H:i:s', $value);
|
$value = date('Y-m-d H:i:s', $value);
|
||||||
|
|
||||||
} else if(in_array($subfield, array('template', 'templates_id'))) {
|
} else if(in_array($subfield, array('template', 'templates_id'))) {
|
||||||
$template = $this->templates->get($subfield);
|
$template = $this->templates->get($value);
|
||||||
$value = $template ? $template->id : 0;
|
$value = $template ? $template->id : 0;
|
||||||
$subfield = 'templates_id';
|
$subfield = 'templates_id';
|
||||||
|
|
||||||
@@ -1236,6 +1236,9 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
|||||||
*/
|
*/
|
||||||
public function ___getSelectorInfo(Field $field, array $data = array()) {
|
public function ___getSelectorInfo(Field $field, array $data = array()) {
|
||||||
|
|
||||||
|
$pages = $this->wire()->pages;
|
||||||
|
$templates = $this->wire()->templates;
|
||||||
|
|
||||||
$info = parent::___getSelectorInfo($field, $data);
|
$info = parent::___getSelectorInfo($field, $data);
|
||||||
if(!isset($data['level'])) $data['level'] = 0;
|
if(!isset($data['level'])) $data['level'] = 0;
|
||||||
$info['input'] = 'page';
|
$info['input'] = 'page';
|
||||||
@@ -1245,29 +1248,34 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
|||||||
$fieldgroups = array();
|
$fieldgroups = array();
|
||||||
$template_ids = self::getTemplateIDs($field);
|
$template_ids = self::getTemplateIDs($field);
|
||||||
$parent_id = $field->get('parent_id');
|
$parent_id = $field->get('parent_id');
|
||||||
|
$templateOptions = array();
|
||||||
|
|
||||||
if($template_ids) {
|
if($template_ids) {
|
||||||
// determine fieldgroup(s) from template setting
|
// determine fieldgroup(s) from template setting
|
||||||
// template_id can be int or array of ints
|
// template_id can be int or array of ints
|
||||||
foreach($template_ids as $tid) {
|
foreach($template_ids as $tid) {
|
||||||
$template = $this->wire('templates')->get((int) $tid);
|
$template = $templates->get((int) $tid);
|
||||||
if($template) $fieldgroups[] = $template->fieldgroup;
|
if(!$template) continue;
|
||||||
|
$fieldgroups[] = $template->fieldgroup;
|
||||||
|
$templateOptions[$template->id] = $template->getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if($parent_id) {
|
} else if($parent_id) {
|
||||||
// determine fieldgroup(s) from family settings
|
// determine fieldgroup(s) from family settings
|
||||||
$parent = $this->wire('pages')->get((int) $parent_id);
|
$parent = $pages->get((int) $parent_id);
|
||||||
if($parent->id) {
|
if($parent->id) {
|
||||||
foreach($parent->template->childTemplates as $template_id) {
|
foreach($parent->template->childTemplates as $template_id) {
|
||||||
$template = $this->wire('templates')->get((int) $template_id);
|
$template = $templates->get((int) $template_id);
|
||||||
if(!$template) continue;
|
if(!$template) continue;
|
||||||
$fieldgroups[$template->fieldgroup->id] = $template->fieldgroup;
|
$fieldgroups[$template->fieldgroup->id] = $template->fieldgroup;
|
||||||
|
$templateOptions[$template->id] = $template->getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->wire('templates') as $template) {
|
foreach($templates as $template) {
|
||||||
if(!in_array($parent->template->id, $template->parentTemplates)) continue;
|
if(!in_array($parent->template->id, $template->parentTemplates)) continue;
|
||||||
if(!$this->wire('pages')->count("parent=$parent_id, template=$template->id, include=all")) continue;
|
if(!$pages->count("parent=$parent_id, template=$template->id, include=all")) continue;
|
||||||
$fieldgroups[$template->fieldgroup->id] = $template->fieldgroup;
|
$fieldgroups[$template->fieldgroup->id] = $template->fieldgroup;
|
||||||
|
$templateOptions[$template->id] = $template->getLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1277,6 +1285,12 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
|||||||
//$fieldgroups[] = $this->wire('fields');
|
//$fieldgroups[] = $this->wire('fields');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!count($templateOptions)) {
|
||||||
|
foreach($templates as $template) {
|
||||||
|
$templateOptions[$template->id] = $template->getLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($fieldgroups as $fieldgroup) {
|
foreach($fieldgroups as $fieldgroup) {
|
||||||
foreach($fieldgroup as $f) {
|
foreach($fieldgroup as $f) {
|
||||||
if(!$f->type) continue;
|
if(!$f->type) continue;
|
||||||
@@ -1292,6 +1306,13 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
|||||||
'input' => 'number',
|
'input' => 'number',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$subfields['templates_id'] = array(
|
||||||
|
'name' => 'templates_id',
|
||||||
|
'label' => $this->_('Template'), // Label for 'template' property of a Page
|
||||||
|
'input' => 'select',
|
||||||
|
'options' => $templateOptions,
|
||||||
|
);
|
||||||
|
|
||||||
$info['subfields'] = $subfields;
|
$info['subfields'] = $subfields;
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
|
@@ -270,7 +270,7 @@ function pwModalWindow(href, options, size) {
|
|||||||
$iframe.refresh();
|
$iframe.refresh();
|
||||||
};
|
};
|
||||||
$iframe.setTitle = function(title) {
|
$iframe.setTitle = function(title) {
|
||||||
$iframe.dialog('option', 'title', title);
|
$iframe.dialog('option', 'title', jQuery('<textarea />').text(title).html());
|
||||||
};
|
};
|
||||||
|
|
||||||
return $iframe;
|
return $iframe;
|
||||||
|
2
wire/modules/Jquery/JqueryUI/modal.min.js
vendored
2
wire/modules/Jquery/JqueryUI/modal.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -2958,7 +2958,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
|||||||
$template->noParents = 1;
|
$template->noParents = 1;
|
||||||
$template->parentTemplates = array();
|
$template->parentTemplates = array();
|
||||||
} else {
|
} else {
|
||||||
$template->noParents = 0;
|
if($template->noParents != 0) $template->noParents = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sortfield = $sanitizer->name($input->post('sortfield'));
|
$sortfield = $sanitizer->name($input->post('sortfield'));
|
||||||
|
Reference in New Issue
Block a user