From 0e045ad45d6b58c38b77b6a2f8e3767f443e03f6 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 14 Feb 2020 14:43:55 -0500 Subject: [PATCH] Add new $field->editUrl() method --- wire/core/Field.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wire/core/Field.php b/wire/core/Field.php index cbc2a95a..2ca0b554 100644 --- a/wire/core/Field.php +++ b/wire/core/Field.php @@ -1394,6 +1394,26 @@ class Field extends WireData implements Saveable, Exportable { return $this->setTags($tagList, false); } + /** + * Get URL to edit field in the admin + * + * @param array|bool|string $options Specify array of options, string for find option, or bool for http option. + * - `find` (string): Name of field to find in editor form + * - `http` (bool): True to force inclusion of scheme and hostname + * @return string + * @since 3.0.151 + * + */ + public function editUrl($options = array()) { + if(is_string($options)) $options = array('find' => $options); + if(is_bool($options)) $options = array('http' => $options); + if(!is_array($options)) $options = array(); + $url = $this->wire('config')->urls(empty($options['http']) ? 'admin' : 'httpAdmin'); + $url .= "setup/field/edit?id=$this->id"; + if(!empty($options['find'])) $url .= '#find-' . $this->wire('sanitizer')->fieldName($options['find']); + return $url; + } + /** * debugInfo PHP 5.6+ magic method *