From 8e084a1ba0a581accf6422639e261deea75bb8a0 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 28 Jun 2018 12:56:29 -0400 Subject: [PATCH] =?UTF-8?q?Add=20new=20collapsed=20=E2=80=9CWhat=20pages?= =?UTF-8?q?=20point=20to=20this=20one=3F=E2=80=9D=C2=A0field=20on=20page?= =?UTF-8?q?=20editor=20Settings=20tab.=20This=20also=20demonstrates=20use?= =?UTF-8?q?=20of=20the=20$page->references()=20and=20$page->links();=20met?= =?UTF-8?q?hods.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProcessPageEdit/ProcessPageEdit.module | 68 ++++++++++++++++++- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module index 61b8f300..c458d4a4 100644 --- a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module +++ b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module @@ -50,7 +50,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod return array( 'title' => 'Page Edit', 'summary' => 'Edit a Page', - 'version' => 108, + 'version' => 109, 'permanent' => true, 'permission' => 'page-edit', 'icon' => 'edit', @@ -1218,12 +1218,74 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod // informational sections if(!$this->isPost) { - $wrapper->add($this->buildFormRoles()); - $wrapper->add($this->buildFormInfo()); + $wrapper->add($this->buildFormRoles()); + $wrapper->add($this->buildFormReferences()); + $wrapper->add($this->buildFormInfo()); } + return $wrapper; } + + /** + * Build the Settings > References fieldset on the Page Edit form + * + * @return InputfieldMarkup + * + */ + protected function buildFormReferences() { + + /** @var InputfieldMarkup $field */ + $field = $this->modules->get('InputfieldMarkup'); + $field->attr('id', 'ProcessPageEditReferences'); + $field->label = $this->_('What pages point to this one?'); + $field->icon = 'link'; + $field->collapsed = Inputfield::collapsedYesAjax; + + if($this->input->get('renderInputfieldAjax') != 'ProcessPageEditReferences') return $field; + + $links = $this->page->links("include=all, limit=100"); + $references = $this->page->references("include=all, limit=100"); + + $numTotal = $references->getTotal() + $links->getTotal(); + $numShown = $references->count() + $links->count(); + $numNotShown = $numTotal - $numShown; + $labelNotListable = $this->_('Not listable'); + + if($numTotal) { + $field->description = sprintf( + $this->_('Found %d other page(s) pointing to this one in Page fields or href links.'), + $numTotal + ); + $out = ""; + if($numNotShown) { + $out .= "
" . sprintf($this->_('%d additional pages not shown.'), $numNotShown) . "
"; + } + } else { + $out = "

" . $this->_('Did not find any other pages pointing to this one in page fields or href links.') . "

"; + } + + $field->value = $out; + + return $field; + } /** * Build the Settings > Info fieldset on the Page Edit form