1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 09:44:38 +02:00

Adjustment to ProcessPageEditLink.module to correct debug mode warnings that appear when called from inside a CKEditor field that's in a repeater

This commit is contained in:
Ryan Cramer
2016-11-20 06:48:52 -05:00
parent d013ef8550
commit 3647a47b86

View File

@@ -14,13 +14,12 @@
* @property int $urlType * @property int $urlType
* @property int $extLinkRel * @property int $extLinkRel
* @property string $extLinkTarget * @property string $extLinkTarget
* @property string $extLinkClass
* *
*/ */
class ProcessPageEditLink extends Process implements ConfigurableModule { class ProcessPageEditLink extends Process implements ConfigurableModule {
protected $page = null;
public static function getModuleInfo() { public static function getModuleInfo() {
return array( return array(
'title' => 'Page Edit Link', 'title' => 'Page Edit Link',
@@ -36,6 +35,18 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
const urlTypeRelativeBranch = 1; const urlTypeRelativeBranch = 1;
const urlTypeRelativeAll = 2; const urlTypeRelativeAll = 2;
/**
* @var Page|null
*
*/
protected $page = null;
/**
* The "choose page" start label
*
* @var string
*
*/
protected $startLabel = ''; protected $startLabel = '';
/** /**
@@ -46,6 +57,12 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
*/ */
protected $langID = 0; protected $langID = 0;
/**
* Get default configuration settings
*
* @return array
*
*/
public static function getDefaultSettings() { public static function getDefaultSettings() {
return array( return array(
'classOptions' => "", 'classOptions' => "",
@@ -58,6 +75,10 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
); );
} }
/**
* Construct
*
*/
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
foreach(self::getDefaultSettings() as $key => $value) { foreach(self::getDefaultSettings() as $key => $value) {
@@ -65,19 +86,24 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
} }
} }
/**
* Init
*
* @throws WireException
*
*/
public function init() { public function init() {
$this->startLabel = $this->_('Choose page'); $this->startLabel = $this->_('Choose page');
$this->modules->get("ProcessPageList"); $this->modules->get("ProcessPageList");
$id = (int) $this->input->get->id; $id = (int) $this->input->get('id');
$this->langID = (int) $this->input->get->lang; $this->langID = (int) $this->input->get('lang');
if($id) $this->page = $this->pages->get($id); if($id) $this->page = $this->pages->get($id);
if($this->page && $this->page->id && !$this->user->hasPermission("page-view", $this->page)) throw new WireException("You don't have access to this page"); if($this->page && $this->page->id && !$this->user->hasPermission("page-view", $this->page)) {
throw new WireException("You don't have access to this page");
}
if(!$this->page) $this->page = $this->wire('pages')->newNullPage(); if(!$this->page) $this->page = $this->wire('pages')->newNullPage();
//$target = $this->sanitizer->name($this->input->get->target);
//$this->config->js('ProcessPageEditLinkTarget', $target);
$this->config->js('ProcessPageEditLink', array( $this->config->js('ProcessPageEditLink', array(
'selectStartLabel' => $this->startLabel, 'selectStartLabel' => $this->startLabel,
'langID' => $this->langID, 'langID' => $this->langID,
@@ -95,6 +121,12 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
parent::init(); parent::init();
} }
/**
* Primary execute
*
* @return string
*
*/
public function ___execute() { public function ___execute() {
if($this->wire('input')->get('href')) { if($this->wire('input')->get('href')) {
@@ -106,17 +138,20 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
$currentValue = ''; $currentValue = '';
} }
/** @var InputfieldForm $form */
$form = $this->modules->get("InputfieldForm"); $form = $this->modules->get("InputfieldForm");
$form->attr('id', 'ProcessPageEditLinkForm'); $form->attr('id', 'ProcessPageEditLinkForm');
//$form->description = $this->_("Enter a URL, select a page, or select a file to link:"); // Headline //$form->description = $this->_("Enter a URL, select a page, or select a file to link:"); // Headline
$this->wire('modules')->get('JqueryWireTabs'); $this->wire('modules')->get('JqueryWireTabs');
/** @var InputfieldWrapper $fieldset */
$fieldset = $this->wire(new InputfieldWrapper()); $fieldset = $this->wire(new InputfieldWrapper());
$fieldset->attr('title', $this->_('Link')); $fieldset->attr('title', $this->_('Link'));
$fieldset->addClass('WireTab'); $fieldset->addClass('WireTab');
$form->add($fieldset); $form->add($fieldset);
/** @var InputfieldPageAutocomplete $field */
$field = $this->modules->get("InputfieldPageAutocomplete"); $field = $this->modules->get("InputfieldPageAutocomplete");
$field->label = $this->_('Link to URL'); $field->label = $this->_('Link to URL');
$field->attr('id+name', 'link_page_url'); $field->attr('id+name', 'link_page_url');
@@ -142,6 +177,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
if(is_array($this->wire('input')->get('anchors'))) { if(is_array($this->wire('input')->get('anchors'))) {
$field->columnWidth = 60; $field->columnWidth = 60;
/** @var InputfieldSelect $field */
$field = $this->modules->get('InputfieldSelect'); $field = $this->modules->get('InputfieldSelect');
$field->columnWidth = 40; $field->columnWidth = 40;
$field->attr('id+name', 'link_page_anchor'); $field->attr('id+name', 'link_page_anchor');
@@ -156,10 +192,11 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
$fieldset->add($field); $fieldset->add($field);
} }
/** @var InputfieldInteger $field */
$field = $this->modules->get('InputfieldInteger'); $field = $this->modules->get('InputfieldInteger');
$field->attr('id+name', 'link_page_id'); $field->attr('id+name', 'link_page_id');
$field->label = $this->_("Select Page"); $field->label = $this->_("Select Page");
$field->startLabel = $this->startLabel; $field->set('startLabel', $this->startLabel);
$field->collapsed = Inputfield::collapsedYes; $field->collapsed = Inputfield::collapsedYes;
$field->icon = 'sitemap'; $field->icon = 'sitemap';
$fieldset->add($field); $fieldset->add($field);
@@ -169,7 +206,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
$field->attr('id+name', 'child_page_id'); $field->attr('id+name', 'child_page_id');
$field->label = $this->_("Select Child Page"); $field->label = $this->_("Select Child Page");
$field->description = $this->_('This is the same as "Select Page" above, but may quicker to use if linking to children of the current page.'); $field->description = $this->_('This is the same as "Select Page" above, but may quicker to use if linking to children of the current page.');
$field->startLabel = $this->startLabel; $field->set('startLabel', $this->startLabel);
$field->collapsed = Inputfield::collapsedYes; $field->collapsed = Inputfield::collapsedYes;
$field->icon = 'sitemap'; $field->icon = 'sitemap';
$fieldset->append($field); $fieldset->append($field);
@@ -193,6 +230,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
$fieldset->add($field); $fieldset->add($field);
if($this->targetOptions) { if($this->targetOptions) {
/** @var InputfieldSelect $field */
$field = $this->modules->get('InputfieldSelect'); $field = $this->modules->get('InputfieldSelect');
$field->attr('id+name', 'link_target'); $field->attr('id+name', 'link_target');
$field->label = $this->_('Target'); $field->label = $this->_('Target');
@@ -200,16 +238,6 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
$this->addSelectOptions($field, 'target', $this->targetOptions); $this->addSelectOptions($field, 'target', $this->targetOptions);
if($this->relOptions) $field->columnWidth = 50; if($this->relOptions) $field->columnWidth = 50;
$fieldset->add($field); $fieldset->add($field);
/*
} else {
$field = $this->modules->get("InputfieldCheckbox");
$field->label = $this->_("Launch In New Window?");
$field->description = $this->_("If checked, the link will open in a new window leaving the current window in place."); // Details for 'launch in new window' checkbox
$field->attr('name', 'link_target');
$field->attr('id', 'link_target_blank');
$field->attr('value', '_blank');
$fieldset->add($field);
*/
} }
if($this->relOptions) { if($this->relOptions) {
@@ -223,6 +251,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
} }
if($this->classOptions) { if($this->classOptions) {
/** @var InputfieldCheckboxes $field */
$field = $this->modules->get('InputfieldCheckboxes'); $field = $this->modules->get('InputfieldCheckboxes');
$field->attr('id+name', 'link_class'); $field->attr('id+name', 'link_class');
$field->label = $this->_('Class'); $field->label = $this->_('Class');
@@ -241,6 +270,12 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
return $form->render() . "<p class='detail ui-priority-secondary'><code id='link_markup'></code></p>"; return $form->render() . "<p class='detail ui-priority-secondary'><code id='link_markup'></code></p>";
} }
/**
* @param InputfieldSelect $field
* @param $attrName
* @param $optionsText
*
*/
protected function addSelectOptions(InputfieldSelect $field, $attrName, $optionsText) { protected function addSelectOptions(InputfieldSelect $field, $attrName, $optionsText) {
$isExisting = $this->wire('input')->get('href') != ''; $isExisting = $this->wire('input')->get('href') != '';
@@ -283,6 +318,13 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
} }
} }
/**
* Return JSON containing files list for ajax use
*
* @return string
* @throws WireException
*
*/
public function ___executeFiles() { public function ___executeFiles() {
if(!$this->page->id) throw new WireException("A page id must be specified"); if(!$this->page->id) throw new WireException("A page id must be specified");
$files = $this->getFiles(); $files = $this->getFiles();
@@ -292,7 +334,6 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
/** /**
* Get array of info about files attached to given Page * Get array of info about files attached to given Page
* *
* @param Page $page
* @return array Associative array of "/url/to/file.pdf" => "Field label: basename" * @return array Associative array of "/url/to/file.pdf" => "Field label: basename"
* *
*/ */
@@ -302,6 +343,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
// As the link generator might be called in a repeater, we need to find the containing page // As the link generator might be called in a repeater, we need to find the containing page
$n = 0; $n = 0;
while(strpos($page->className(), 'Repeater') !== false && ++$n < 10) { while(strpos($page->className(), 'Repeater') !== false && ++$n < 10) {
/** @var RepeaterPage $page */
$page = $page->getForPage(); $page = $page->getForPage();
} }
if($page->id) { if($page->id) {
@@ -315,6 +357,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
* Get array of info about files attached to given Page, including any repeater items * Get array of info about files attached to given Page, including any repeater items
* *
* @param Page $page * @param Page $page
* @param string $prefix
* @return array Associative array of "/url/to/file.pdf" => "Field label: basename" * @return array Associative array of "/url/to/file.pdf" => "Field label: basename"
* *
*/ */
@@ -324,11 +367,13 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
/** @var Fieldtype $type */ /** @var Fieldtype $type */
$type = $field->type; $type = $field->type;
if($type instanceof FieldtypeFile) { if($type instanceof FieldtypeFile) {
foreach($page->get($field->name) as $file) { $value = $page->get($field->name);
if($value) foreach($page->get($field->name) as $file) {
$files[$file->url] = $prefix . $field->getLabel() . ': ' . $file->basename; $files[$file->url] = $prefix . $field->getLabel() . ': ' . $file->basename;
} }
} else if(strpos($type->className(), 'FieldtypeRepeater') !== false) { } else if(strpos($type->className(), 'FieldtypeRepeater') !== false) {
foreach($page->get($field->name) as $repeaterPage){ $value = $page->get($field->name);
if($value) foreach($page->get($field->name) as $repeaterPage){
$files = array_merge($this->getFilesPage($repeaterPage, $field->getLabel() . ': '), $files); $files = array_merge($this->getFilesPage($repeaterPage, $field->getLabel() . ': '), $files);
} }
} }
@@ -336,7 +381,12 @@ class ProcessPageEditLink extends Process implements ConfigurableModule {
return $files; return $files;
} }
/**
* @return InputfieldSelect
*
*/
protected function getFilesField() { protected function getFilesField() {
/** @var InputfieldSelect $field */
$field = $this->modules->get("InputfieldSelect"); $field = $this->modules->get("InputfieldSelect");
$field->label = $this->_("Select File"); $field->label = $this->_("Select File");
$field->attr('id+name', 'link_page_file'); $field->attr('id+name', 'link_page_file');