-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENHANCEMENT Replaced client side URL filtering in CMS with ajax callb…
…acks to new SiteTreeURLSegmentField, in order to align with extended server side logic (and avoid pre-filtering values too heavily before passing them to the server). Removed suggestions from client side user confirmation.
- Loading branch information
Showing
3 changed files
with
77 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
<?php | |||
/** | |||
* @package cms | |||
* @subpackage forms | |||
*/ | |||
|
|||
/** | |||
* Used to edit the SiteTree->URLSegment property, and suggest input based on the serverside rules | |||
* defined through {@link SiteTree->generateURLSegment()} and {@link URLSegmentFilter}. | |||
* | |||
* Note: The actual conversion for saving the value takes place in the model layer. | |||
*/ | |||
class SiteTreeURLSegmentField extends TextField { | |||
|
|||
static $allowed_actions = array( | |||
'suggest' | |||
); | |||
|
|||
function suggest($request) { | |||
if(!$request->getVar('value')) return $this->httpError(405); | |||
$page = $this->getPage(); | |||
|
|||
// Same logic as SiteTree->onBeforeWrite | |||
$page->URLSegment = $page->generateURLSegment($request->getVar('value')); | |||
$count = 2; | |||
while(!$page->validURLSegment()) { | |||
$page->URLSegment = preg_replace('/-[0-9]+$/', null, $page->URLSegment) . '-' . $count; | |||
$count++; | |||
} | |||
|
|||
Controller::curr()->getResponse()->addHeader('Content-Type', 'application/json'); | |||
return Convert::raw2json(array('value' => $page->URLSegment)); | |||
} | |||
|
|||
/** | |||
* @return SiteTree | |||
*/ | |||
function getPage() { | |||
$idField = $this->getForm()->dataFieldByName('ID'); | |||
return ($idField && $idField->Value()) ? DataObject::get_by_id('SiteTree', $idField->Value()) : singleton('SiteTree'); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters