Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.7.0: New Feature=>editor-xtd to insert menu items links in content #11721

Merged
merged 5 commits into from
Aug 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ protected function updateManifestCaches()
array('plugin', 'folderinstaller', 'installer', 0),
array('plugin', 'urlinstaller', 'installer', 0),
array('plugin', 'phpversioncheck', 'quickicon', 0),
array('plugin', 'menu', 'editors-xtd', 0),

// Templates
array('template', 'beez3', '', 0),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(459, 'plg_editors-xtd_menu', 'plugin', 'menu', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES
(459, 'plg_editors-xtd_menu', 'plugin', 'menu', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the orderering be "5"? (look at the other editor-xtd plugins sql)
(same for all other sql)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based my update sql on the last editors-xtd_module added to core.
Example:

INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES
(453, 'plg_editors-xtd_module', 'plugin', 'module', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET IDENTITY_INSERT [#__extensions] ON;

INSERT INTO [#__extensions] ([extension_id], [name], [type], [element], [folder], [client_id], [enabled], [access], [protected], [manifest_cache], [params], [custom_data], [system_data], [checked_out], [checked_out_time], [ordering], [state])
SELECT 459, 'plg_editors-xtd_menu', 'plugin', 'menu', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0;

SET IDENTITY_INSERT [#__extensions] OFF;
8 changes: 8 additions & 0 deletions administrator/language/en-GB/en-GB.plg_editors-xtd_menu.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; Joomla! Project
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_EDITORS-XTD_MENU="Button - Menu"
PLG_EDITORS-XTD_MENU_BUTTON_MENU="Menu"
PLG_EDITORS-XTD_MENU_XML_DESCRIPTION="Displays a button to make it possible to insert menu item links into an Article. Displays a popup allowing you to choose the menu item."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_EDITORS-XTD_MENU="Button - Menu"
PLG_EDITORS-XTD_MENU_XML_DESCRIPTION="Displays a button to make it possible to insert menu item links into an Article. Displays a popup allowing you to choose the menu item."
2 changes: 2 additions & 0 deletions administrator/language/en-GB/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
<filename>en-GB.plg_editors-xtd_article.sys.ini</filename>
<filename>en-GB.plg_editors-xtd_image.ini</filename>
<filename>en-GB.plg_editors-xtd_image.sys.ini</filename>
<filename>en-GB.plg_editors-xtd_menu.ini</filename>
<filename>en-GB.plg_editors-xtd_menu.sys.ini</filename>
<filename>en-GB.plg_editors-xtd_module.ini</filename>
<filename>en-GB.plg_editors-xtd_module.sys.ini</filename>
<filename>en-GB.plg_editors-xtd_pagebreak.ini</filename>
Expand Down
1 change: 1 addition & 0 deletions installation/sql/mysql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`
(456, 'plg_installer_folderinstaller', 'plugin', 'folderinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 2, 0),
(457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 3, 0),
(458, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(459, 'plg_editors-xtd_menu', 'plugin', 'menu', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(503, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(504, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(506, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
Expand Down
3 changes: 2 additions & 1 deletion installation/sql/postgresql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder"
(455, 'plg_installer_packageinstaller', 'plugin', 'packageinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 1, 0),
(456, 'plg_installer_folderinstaller', 'plugin', 'folderinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 2, 0),
(457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 3, 0),
(458, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0);
(458, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(459, 'plg_editors-xtd_menu', 'plugin', 'menu', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0);

-- Templates
INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES
Expand Down
4 changes: 3 additions & 1 deletion installation/sql/sqlazure/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,9 @@ SELECT 456, 'plg_installer_folderinstaller', 'plugin', 'folderinstaller', 'insta
UNION ALL
SELECT 457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 3, 0
UNION ALL
SELECT 458, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0;
SELECT 458, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0
UNION ALL
SELECT 459, 'plg_editors-xtd_menu', 'plugin', 'menu', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0;

INSERT [#__extensions] ([extension_id], [name], [type], [element], [folder], [client_id], [enabled], [access], [protected], [manifest_cache], [params], [custom_data], [system_data], [checked_out], [checked_out_time], [ordering], [state])
SELECT 503, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1900-01-01 00:00:00', 0, 0
Expand Down
75 changes: 75 additions & 0 deletions plugins/editors-xtd/menu/menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors-xtd.menu
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

/**
* Editor menu buton
*
* @since __DEPLOY_VERSION__
*/
class PlgButtonMenu extends JPlugin
{
/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;

/**
* Display the button
*
* @param string $name The name of the button to add
*
* @since __DEPLOY_VERSION__
* @return array
*/
public function onDisplay($name)
{
/*
* Javascript to insert the link
* View element calls jSelectMenuItem when a menu item is clicked
* jSelectMenuItem creates the link tag, sends it to the editor,
* and closes the select frame.
*/
$js = "
function jSelectMenuItem(id, title, tree, object, uri, language)
{
var thislang = '';
if (language !== '')
{
var thislang = '&lang=';
}
var tag = '<a href=\"' + uri + thislang + language + '\">' + title + '</a>';
jInsertEditorText(tag, '" . $name . "');
jModalClose();
}";

Copy link
Contributor

@dgrammatiko dgrammatiko Aug 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@infograf768 this script should be on the modal view, so it can be overridden if someone decides to change the view.
It's a simple change:

  • cut the lines 43-57 and paste them in the modal view.
  • change line 63 to $link = 'index.php?option=com_menus&amp;view=items&amp;layout=modal&amp;tmpl=component&amp;name=' . $name . '&amp;' . JSession::getFormToken() . '=1';
  • add one line like ` $name = JFactory::getApplication()->input->get('name', '', 'url'); in the first lines of the modal view

Check the xtd-modules and the modules/modal.php:
https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_modules/views/modules/tmpl/modal.php#L27-L37

$editor    = JFactory::getApplication()->input->get('editor', '', 'cmd');
JFactory::getDocument()->addScriptDeclaration('
moduleIns = function(type, name) {
    window.parent.jInsertEditorText("{loadmodule " + type + "," + name + "}", "' . $editor . '");
    window.parent.jModalClose();
};
modulePosIns = function(position) {
    window.parent.jInsertEditorText("{loadposition " + position + "}", "' . $editor . '");
    window.parent.jModalClose();
};');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based this proposal on the editors-xtd_article as a good soldier.
If you think this solution should generally be used in core, then it should also for the editors-xtd_article.
I will let you do that in a specific PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@infograf768 Actually I tried to do that with #10794 but I messed up things there

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose therefore to let the js in the xtd (in both) as anyway it will be used only when the editor is in use and the plugin is enabled, which imho is better.

$doc = JFactory::getDocument();
$doc->addScriptDeclaration($js);

/*
* Use the built-in element view to select the menu item.
* Currently uses blank class.
*/
$link = 'index.php?option=com_menus&amp;view=items&amp;layout=modal&amp;tmpl=component&amp;' . JSession::getFormToken() . '=1';

$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link = $link;
$button->text = JText::_('PLG_EDITORS-XTD_MENU_BUTTON_MENU');
$button->name = 'share-alt';
$button->options = "{handler: 'iframe', size: {x: 800, y: 500}}";

return $button;
}
}
19 changes: 19 additions & 0 deletions plugins/editors-xtd/menu/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.7" type="plugin" group="editors-xtd" method="upgrade">
<name>plg_editors-xtd_menu</name>
<author>Joomla! Project</author>
<creationDate>August 2016</creationDate>
<copyright>Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>__DEPLOY_VERSION__</version>
<description>PLG_EDITORS-XTD_MENU_XML_DESCRIPTION</description>
<files>
<filename plugin="menu">menu.php</filename>
</files>
<languages>
<language tag="en-GB">en-GB.plg_editors-xtd_menu.ini</language>
<language tag="en-GB">en-GB.plg_editors-xtd_menu.sys.ini</language>
</languages>
</extension>