Skip to content

Commit

Permalink
[4.2] Menu item custom field (joomla#38244)
Browse files Browse the repository at this point in the history
* [4.2] Menu item custom field

* Update menuitem.php

* Thanks @richard67

* less haste more speed
  • Loading branch information
brianteeman authored Jul 13, 2022
1 parent a354423 commit 32ef564
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
(0, 'plg_fields_menuitem', 'plugin', 'menuitem', 'fields', 0, 1, 1, 0, 1, '', '', '', 0, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
(0, 'plg_fields_menuitem', 'plugin', 'menuitem', 'fields', 0, 1, 1, 0, 1, '', '', '', 0, 0);
8 changes: 8 additions & 0 deletions administrator/language/en-GB/plg_fields_menuitem.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; Joomla! Project
; (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_FIELDS_MENUITEM="Fields - Menu Item"
PLG_FIELDS_MENUITEM_LABEL="List of Menu Items (%s)"
PLG_FIELDS_MENUITEM_XML_DESCRIPTION="This plugin lets you create new fields of type 'menuitem' in any extensions where custom fields are supported."
7 changes: 7 additions & 0 deletions administrator/language/en-GB/plg_fields_menuitem.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_FIELDS_MENUITEM="Fields - Menu Item"
PLG_FIELDS_MENUITEM_XML_DESCRIPTION="This plugin lets you create new fields of type 'menuitem' in any extensions where custom fields are supported."
17 changes: 9 additions & 8 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,15 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_fields_integer', 'plugin', 'integer', 'fields', 0, 1, 1, 0, 1, '', '{"multiple":"0","first":"1","last":"100","step":"1"}', '', 6, 0),
(0, 'plg_fields_list', 'plugin', 'list', 'fields', 0, 1, 1, 0, 1, '', '', '', 7, 0),
(0, 'plg_fields_media', 'plugin', 'media', 'fields', 0, 1, 1, 0, 1, '', '', '', 8, 0),
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 9, 0),
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0),
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0),
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0),
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_fields_menuitem', 'plugin', 'menuitem', 'fields', 0, 1, 1, 0, 1, '', '', '', 9, 0),
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0),
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0),
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0),
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0),
(0, 'plg_filesystem_local', 'plugin', 'local', 'filesystem', 0, 1, 1, 0, 1, '', '{}', '', 1, 0),
(0, 'plg_finder_categories', 'plugin', 'categories', 'finder', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_finder_contacts', 'plugin', 'contacts', 'finder', 0, 1, 1, 0, 1, '', '', '', 2, 0),
Expand Down
17 changes: 9 additions & 8 deletions installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,15 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_fields_integer', 'plugin', 'integer', 'fields', 0, 1, 1, 0, 1, '', '{"multiple":"0","first":"1","last":"100","step":"1"}', '', 6, 0),
(0, 'plg_fields_list', 'plugin', 'list', 'fields', 0, 1, 1, 0, 1, '', '', '', 7, 0),
(0, 'plg_fields_media', 'plugin', 'media', 'fields', 0, 1, 1, 0, 1, '', '', '', 8, 0),
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 9, 0),
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0),
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0),
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0),
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_fields_menuitem', 'plugin', 'menuitem', 'fields', 0, 1, 1, 0, 1, '', '', '', 9, 0),
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0),
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0),
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0),
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0),
(0, 'plg_filesystem_local', 'plugin', 'local', 'filesystem', 0, 1, 1, 0, 1, '', '{}', '', 1, 0),
(0, 'plg_finder_categories', 'plugin', 'categories', 'finder', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_finder_contacts', 'plugin', 'contacts', 'finder', 0, 1, 1, 0, 1, '', '', '', 2, 0),
Expand Down
1 change: 1 addition & 0 deletions libraries/src/Extension/ExtensionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class ExtensionHelper
array('plugin', 'integer', 'fields', 0),
array('plugin', 'list', 'fields', 0),
array('plugin', 'media', 'fields', 0),
array('plugin', 'menuitem', 'fields', 0),
array('plugin', 'radio', 'fields', 0),
array('plugin', 'sql', 'fields', 0),
array('plugin', 'subform', 'fields', 0),
Expand Down
20 changes: 20 additions & 0 deletions plugins/fields/menuitem/menuitem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Fields.Menuitem
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

/**
* Fields Menuitem Plugin
*
* @since __DEPLOY_VERSION__
*/
class PlgFieldsMenuitem extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin
{
}
20 changes: 20 additions & 0 deletions plugins/fields/menuitem/menuitem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<extension type="plugin" group="fields" method="upgrade">
<name>plg_fields_menuitem</name>
<author>Joomla! Project</author>
<creationDate>2022-07</creationDate>
<copyright>(C) 2022 Open Source Matters, Inc.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>4.2.0</version>
<description>PLG_FIELDS_MENUITEM_XML_DESCRIPTION</description>
<files>
<filename plugin="menuitem">menuitem.php</filename>
<folder>tmpl</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_fields_menuitem.ini</language>
<language tag="en-GB">language/en-GB/plg_fields_menuitem.sys.ini</language>
</languages>
</extension>
22 changes: 22 additions & 0 deletions plugins/fields/menuitem/tmpl/menuitem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Fields.Menuitem
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

$value = $field->value;

if ($value == '') {
return;
}

$url = \Joomla\CMS\Router\Route::_("index.php?Itemid={$value}");
$title = \Joomla\CMS\Factory::getApplication()->getMenu()->getItem($value)->title;

echo "<a href=\"{$url}\">{$title}</a>";

0 comments on commit 32ef564

Please sign in to comment.