Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name Format Children #831

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 27 additions & 52 deletions wire/core/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ class Pages extends Wire {
*/
protected $config = null;

/**
* Are we currently cloning a page?
*
* This is true only when the clone() method is currently in progress.
*
* @var bool
*
*/
protected $cloning = false;

/**
* Name for autogenerated page names when fields to generate name aren't populated
*
Expand Down Expand Up @@ -559,11 +549,10 @@ public function count($selectorString, array $options = array()) {
* @param Page $page
* @param string $reason Text containing the reason why it can't be saved (assuming it's not saveable)
* @param string $fieldName Optional fieldname to limit check to.
* @param array $options Options array given to the original save method (optional)
* @return bool True if saveable, False if not
*
*/
public function isSaveable(Page $page, &$reason, $fieldName = '', array $options = array()) {
public function isSaveable(Page $page, &$reason, $fieldName = '') {

$saveable = false;
$outputFormattingReason = "Call \$page->setOutputFormatting(false) before getting/setting values that will be modified and saved. ";
Expand Down Expand Up @@ -611,9 +600,8 @@ public function isSaveable(Page $page, &$reason, $fieldName = '', array $options
}
}

// FAMILY CHECKS
// check for a parent change and whether it is allowed
if($saveable && $page->parentPrevious && $page->parentPrevious->id != $page->parent->id && empty($options['ignoreFamily'])) {
// check for a parent change
if($saveable && $page->parentPrevious && $page->parentPrevious->id != $page->parent->id) {
// page was moved
if($page->template->noMove && ($page->is(Page::statusSystem) || $page->is(Page::statusSystemID) || !$page->isTrash())) {
// make sure the page's template allows moves. only move laways allowed is to the trash, unless page has system status
Expand Down Expand Up @@ -730,27 +718,26 @@ public function ___setupPageName(Page $page, array $options = array()) {

$pageName = '';

if(strlen($format)) {
// @todo add option to auto-gen name from any page property/field

if($format == 'title') {
if(strlen($page->title)) $pageName = $page->title;
else $pageName = $this->untitledPageName;

} else if(!ctype_alnum($format) && !preg_match('/^[-_a-zA-Z0-9]+$/', $format)) {
// it is a date format
$pageName = date($format);
} else {

// predefined format
$pageName = $format;
}

} else if(strlen($page->title)) {
$pageName = $page->title;
/* allows 3 types of format for name and title, which could be combined in endless variations each separated by comma
*
* - type date: if function detects # character anywhere in the string conversion: delete #, date($format)
* - type field: if string is a fieldname of the parent page conversion: value of this field
* - type string: if string doesn't fit to the 2 preceeding it will be taken as it is
*
* - all parts (separated by comma) will be composed in the order of setting
*
*
*/

} else {
// no name will be assigned
if(strlen($format)) {
$format = explode(',',$format);
foreach ($format as $autoName) {
$autoName = str_replace('#','',$autoName,$count); // could also any other reserved character
if ($count) $page->title .= date($autoName);
elseif ($page->parent()->$autoName) $page->title .= $page->parent()->$autoName;
else $page->title .= $autoName;
}
$pageName = $page->title;
}

if($pageName == $this->untitledPageName && strpos($page->name, $this->untitledPageName) === 0) {
Expand Down Expand Up @@ -796,7 +783,6 @@ public function ___setupPageName(Page $page, array $options = array()) {
* 'quiet' => boolean - When true, modified date and modified_users_id won't be updated (default=false)
* 'adjustName' => boolean - Adjust page name to ensure it is unique within its parent (default=false)
* 'forceID' => integer - use this ID instead of an auto-assigned on (new page) or current ID (existing page)
* 'ignoreFamily' => boolean - Bypass check of allowed family/parent settings when saving (default=false)
* @return bool True on success, false on failure
* @throws WireException
*
Expand All @@ -807,8 +793,7 @@ public function ___save(Page $page, $options = array()) {
'uncacheAll' => true,
'resetTrackChanges' => true,
'adjustName' => false,
'forceID' => 0,
'ignoreFamily' => false,
'forceID' => 0
);

$options = array_merge($defaultOptions, $options);
Expand All @@ -826,7 +811,7 @@ public function ___save(Page $page, $options = array()) {
$isNew = $page->isNew();
if($isNew) $this->setupNew($page);

if(!$this->isSaveable($page, $reason, '', $options)) {
if(!$this->isSaveable($page, $reason)) {
if($language) $user->language = $language;
throw new WireException("Can't save page {$page->id}: {$page->path}: $reason");
}
Expand Down Expand Up @@ -1107,7 +1092,7 @@ public function ___saveField(Page $page, $field, array $options = array()) {

$reason = '';
if($page->isNew()) throw new WireException("Can't save field from a new page - please save the entire page first");
if(!$this->isSaveable($page, $reason, $field, $options)) throw new WireException("Can't save field from page {$page->id}: {$page->path}: $reason");
if(!$this->isSaveable($page, $reason, $field)) throw new WireException("Can't save field from page {$page->id}: {$page->path}: $reason");
if($field && (is_string($field) || is_int($field))) $field = $this->fuel('fields')->get($field);
if(!$field instanceof Field) throw new WireException("Unknown field supplied to saveField for page {$page->id}");
if(!$page->fields->has($field)) throw new WireException("Page {$page->id} does not have field {$field->name}");
Expand Down Expand Up @@ -1383,11 +1368,10 @@ public function ___delete(Page $page, $recursive = false, array $options = array
* - forceID (int): force a specific ID
* - set (array): Array of properties to set to the clone (you can also do this later)
* @return Page the newly cloned page or a NullPage() with id=0 if unsuccessful.
* @throws WireException|Exception on fatal error
*
*/
public function ___clone(Page $page, Page $parent = null, $recursive = true, $options = array()) {

// if parent is not changing, we have to modify name now
if(is_null($parent)) {
$parent = $page->parent;
Expand Down Expand Up @@ -1430,15 +1414,7 @@ public function ___clone(Page $page, Page $parent = null, $recursive = true, $op
$o = $copy->outputFormatting;
$copy->setOutputFormatting(false);
$this->cloneReady($page, $copy);
try {
$this->cloning = true;
$options['ignoreFamily'] = true; // skip family checks during clone
$this->save($copy, $options);
} catch(Exception $e) {
$this->cloning = false;
throw $e;
}
$this->cloning = false;
$this->save($copy, $options);
$copy->setOutputFormatting($o);

// check to make sure the clone has worked so far
Expand Down Expand Up @@ -1610,7 +1586,6 @@ public function sortfields() {
*/
public function __get($key) {
if($key == 'outputFormatting') return $this->outputFormatting;
if($key == 'cloning') return $this->cloning;
return parent::__get($key);
}

Expand Down
2 changes: 1 addition & 1 deletion wire/modules/Inputfield/InputfieldPassword.module
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class InputfieldPassword extends InputfieldText {
*/
public function ___getConfigInputfields() {
$inputfields = parent::___getConfigInputfields();
$skips = array('collapsed', 'placeholder', 'stripTags', 'pattern');
$skips = array('visibility', 'placeholder', 'stripTags', 'pattern');
foreach($skips as $name) {
$f = $inputfields->get($name);
if($f) $inputfields->remove($f);
Expand Down
2 changes: 1 addition & 1 deletion wire/modules/Process/ProcessLogin/ProcessLogin.module
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ProcessLogin extends Process {
}
$home = $this->pages->get("/");
$links .= "<div><a href='{$home->url}'><i class='fa fa-home'></i> {$home->title}</a></div>";
if($links) $out .= "<p>$links</p>";
if($links) $out .= $links;
return $out;
}
}
Expand Down
6 changes: 6 additions & 0 deletions wire/modules/Process/ProcessModule/ProcessModule.module
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,12 @@ class ProcessModule extends Process {
$table->row(array($this->_x('Version', 'edit'), $version));
if(!empty($moduleInfo['created'])) $table->row(array($this->labels['installed_date'], wireRelativeTimeStr($moduleInfo['created'])));
if(!empty($moduleInfo['author'])) $table->row(array($this->_x('Author', 'edit'), $moduleInfo['author']));
if(!empty($moduleInfo['license'])) {
$hreflicense = '';
if(!empty($moduleInfo['hreflicense'])) {
if(substr($moduleInfo['hreflicense'],0,7) != 'http://') $moduleInfo['hreflicense'] = str_replace($moduleName.'.module','',$filename).$moduleInfo['hreflicense'];
$hreflicense = " - <a href='$moduleInfo[hreflicense]'>".$this->_('read more')."</a>";
}
$table->row(array($this->_x('Summary', 'edit'), $moduleInfo['summary']));
if($requirementsStr) $table->row(array($this->_x('Requires', 'edit'), $requirementsStr));
if($dependentsStr) $table->row(array($this->_x('Required By', 'edit'), $dependentsStr));
Expand Down