Skip to content

Commit c1856cf

Browse files
author
David Hurley
committed
Merge pull request #2125 from beat/jux2-frontend-edit-modules
[JUX2] [07] Added front-end hover icon to modules to edit module in backend (with tooltip showing module position)
2 parents b2b61b6 + 63c2f3b commit c1856cf

File tree

15 files changed

+382
-104
lines changed

15 files changed

+382
-104
lines changed

administrator/components/com_config/models/forms/application.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,19 @@
614614
label="COM_CONFIG_FIELD_OFFLINE_IMAGE_LABEL"
615615
description="COM_CONFIG_FIELD_OFFLINE_IMAGE_DESC" />
616616

617+
<field
618+
name="frontediting"
619+
type="list"
620+
default="1"
621+
label="COM_CONFIG_FRONTEDITING_LABEL"
622+
description="COM_CONFIG_FRONTEDITING_DESC"
623+
filter="integer">
624+
<!-- <option value="3">COM_CONFIG_FRONTEDITING_MENUSANDMODULES_ADMIN_TOO</option> -->
625+
<option value="2">COM_CONFIG_FRONTEDITING_MENUSANDMODULES</option>
626+
<option value="1">COM_CONFIG_FRONTEDITING_MODULES</option>
627+
<option value="0">JNONE</option>
628+
</field>
629+
617630
<field
618631
name="editor"
619632
type="plugins"

administrator/components/com_menus/controller.php

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class MenusController extends JControllerLegacy
2121
/**
2222
* Method to display a view.
2323
*
24-
* @param boolean If true, the view output will be cached
25-
* @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
24+
* @param boolean $cachable If true, the view output will be cached
25+
* @param array|boolean $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
2626
*
27-
* @return JController This object to support chaining.
27+
* @return JController This object to support chaining.
2828
* @since 1.5
2929
*/
3030
public function display($cachable = false, $urlparams = false)
@@ -35,26 +35,6 @@ public function display($cachable = false, $urlparams = false)
3535
$layout = $this->input->get('layout', 'default');
3636
$id = $this->input->getInt('id');
3737

38-
// Check for edit form.
39-
if ($view == 'menu' && $layout == 'edit' && !$this->checkEditId('com_menus.edit.menu', $id)) {
40-
41-
// Somehow the person just went to the form - we don't allow that.
42-
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
43-
$this->setMessage($this->getError(), 'error');
44-
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
45-
46-
return false;
47-
}
48-
elseif ($view == 'item' && $layout == 'edit' && !$this->checkEditId('com_menus.edit.item', $id)) {
49-
50-
// Somehow the person just went to the form - we don't allow that.
51-
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
52-
$this->setMessage($this->getError(), 'error');
53-
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=items', false));
54-
55-
return false;
56-
}
57-
5838
parent::display();
5939

6040
return $this;

administrator/components/com_menus/controllers/item.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,6 @@ public function save($key = null, $urlVar = null)
138138
$context = 'com_menus.edit.item';
139139
$recordId = $this->input->getInt('id');
140140

141-
if (!$this->checkEditId($context, $recordId))
142-
{
143-
// Somehow the person just went to the form and saved it - we don't allow that.
144-
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $recordId));
145-
$this->setMessage($this->getError(), 'error');
146-
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=items' . $this->getRedirectToListAppend(), false));
147-
148-
return false;
149-
}
150-
151141
// Populate the row id from the session.
152142
$data['id'] = $recordId;
153143

administrator/components/com_menus/controllers/menu.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ public function save($key = null, $urlVar = null)
4848
$task = $this->getTask();
4949
$recordId = $this->input->getInt('id');
5050

51-
if (!$this->checkEditId($context, $recordId))
52-
{
53-
// Somehow the person just went to the form and saved it - we don't allow that.
54-
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $recordId));
55-
$this->setMessage($this->getError(), 'error');
56-
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
57-
58-
return false;
59-
}
60-
6151
// Make sure we are not trying to modify an administrator menu.
6252
if (isset($data['client_id']) && $data['client_id'] == 1){
6353
JError::raiseNotice(0, JText::_('COM_MENUS_MENU_TYPE_NOT_ALLOWED'));

administrator/components/com_modules/controller.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ class ModulesController extends JControllerLegacy
2121
/**
2222
* Method to display a view.
2323
*
24-
* @param boolean If true, the view output will be cached
25-
* @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
24+
* @param boolean $cachable If true, the view output will be cached
25+
* @param array|boolean $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}
26+
.
2627
*
27-
* @return JController This object to support chaining.
28+
* @return JController This object to support chaining.
2829
* @since 1.5
2930
*/
3031
public function display($cachable = false, $urlparams = false)
@@ -38,17 +39,6 @@ public function display($cachable = false, $urlparams = false)
3839
$layout = $this->input->get('layout', 'default');
3940
$id = $this->input->getInt('id');
4041

41-
// Check for edit form.
42-
if ($view == 'module' && $layout == 'edit' && !$this->checkEditId('com_modules.edit.module', $id))
43-
{
44-
// Somehow the person just went to the form - we don't allow that.
45-
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
46-
$this->setMessage($this->getError(), 'error');
47-
$this->setRedirect(JRoute::_('index.php?option=com_modules&view=modules', false));
48-
49-
return false;
50-
}
51-
52-
parent::display();
42+
return parent::display();
5343
}
5444
}

administrator/language/en-GB/en-GB.com_config.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ COM_CONFIG_FIELD_FILTERS_CUSTOM_BLACK_LIST="Custom Black List"
7171
COM_CONFIG_FIELD_FILTERS_NO_HTML="No HTML"
7272
COM_CONFIG_FIELD_FILTERS_NO_FILTER="No Filtering"
7373
COM_CONFIG_FIELD_FILTERS_WHITE_LIST="White List"
74+
COM_CONFIG_FRONTEDITING_DESC="Select if you want mouse-over edit icons for modules and menu items (support may depend on your template)"
75+
COM_CONFIG_FRONTEDITING_LABEL="Mouse-over edit icons for"
76+
COM_CONFIG_FRONTEDITING_MENUSANDMODULES="Modules & Menus"
77+
COM_CONFIG_FRONTEDITING_MENUSANDMODULES_ADMIN_TOO="Modules & Menus (admin too)"
78+
COM_CONFIG_FRONTEDITING_MODULES="Modules"
7479
COM_CONFIG_FIELD_FORCE_SSL_DESC="Force site access to always occur under SSL (https) for selected areas. You will not be able to access selected areas under non-ssl. Note, you must have SSL enabled on your server to utilise this option."
7580
COM_CONFIG_FIELD_FORCE_SSL_LABEL="Force SSL"
7681
COM_CONFIG_FIELD_FTP_ENABLE_DESC="Enable the built in FTP (File Transfer Protocol) functionality which is needed in some server environments to be used instead of the normal upload functionality of Joomla!"

administrator/language/en-GB/en-GB.lib_joomla.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ JLIB_HTML_DATE_RELATIVE_MINUTES_0="%s minutes ago"
382382
JLIB_HTML_DATE_RELATIVE_WEEKS="%s weeks ago"
383383
JLIB_HTML_DATE_RELATIVE_WEEKS_1="%s week ago"
384384
JLIB_HTML_DATE_RELATIVE_WEEKS_0="%s weeks ago"
385+
JLIB_HTML_EDIT_MENU_ITEM="Edit menu item"
386+
JLIB_HTML_EDIT_MENU_ITEM_ID="Item id: %s"
387+
JLIB_HTML_EDIT_MODULE="Edit module"
388+
JLIB_HTML_EDIT_MODULE_IN_POSITION="Position: %s"
385389
JLIB_HTML_EDITOR_CANNOT_LOAD="Cannot load the editor"
386390
JLIB_HTML_END="End"
387391
JLIB_HTML_ERROR_FUNCTION_NOT_SUPPORTED="Function not supported."

language/en-GB/en-GB.lib_joomla.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ JLIB_HTML_DATE_RELATIVE_MINUTES_0="%s minutes ago"
381381
JLIB_HTML_DATE_RELATIVE_WEEKS="%s weeks ago"
382382
JLIB_HTML_DATE_RELATIVE_WEEKS_1="%s week ago"
383383
JLIB_HTML_DATE_RELATIVE_WEEKS_0="%s weeks ago"
384+
JLIB_HTML_EDIT_MENU_ITEM="Edit menu item"
385+
JLIB_HTML_EDIT_MENU_ITEM_ID="Item id: %s"
386+
JLIB_HTML_EDIT_MODULE="Edit module"
387+
JLIB_HTML_EDIT_MODULE_IN_POSITION="Position: %s"
384388
JLIB_HTML_EDITOR_CANNOT_LOAD="Cannot load the editor"
385389
JLIB_HTML_END="End"
386390
JLIB_HTML_ERROR_FUNCTION_NOT_SUPPORTED="Function not supported."
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* @package Joomla.Site
4+
* @subpackage Layout
5+
*
6+
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
defined('_JEXEC') or die;
11+
12+
// JLayout for standard handling of the edit modules:
13+
14+
$moduleHtml =& $displayData['moduleHtml'];
15+
$mod = $displayData['module'];
16+
$position = $displayData['position'];
17+
$menusEditing = $displayData['menusediting'];
18+
19+
20+
if (preg_match('/<(?:div|span|nav|ul|ol|h\d) [^>]*class="[^"]* jmoddiv"/', $moduleHtml))
21+
{
22+
// Module has already module edit button:
23+
return;
24+
}
25+
26+
// Add css class jmoddiv and data attributes for module-editing URL and for the tooltip:
27+
$editUrl = JURI::base() . 'administrator/index.php?option=com_modules&view=module&layout=edit&id=' . (int) $mod->id;
28+
29+
// Add class, editing URL and tooltip, and if module of type menu, also the tooltip for editing the menu item:
30+
$count = 0;
31+
$moduleHtml = preg_replace(
32+
// Replace first tag of module with a class
33+
'/^(\s*<(?:div|span|nav|ul|ol|h\d) [^>]*class="[^"]*)"/',
34+
// By itself, adding class jmoddiv and data attributes for the url and tooltip:
35+
'\\1 jmoddiv" data-jmodediturl="' . $editUrl . '" data-jmodtip="'
36+
. JHtml::tooltipText(
37+
JText::_('JLIB_HTML_EDIT_MODULE'),
38+
htmlspecialchars($mod->title) . '<br />' . sprintf(JText::_('JLIB_HTML_EDIT_MODULE_IN_POSITION'), htmlspecialchars($position)),
39+
0
40+
)
41+
. '"'
42+
// And if menu editing is enabled and allowed and it's a menu module, add data attributes for menu editing:
43+
. ($menusEditing && $mod->module == 'mod_menu' ?
44+
'" data-jmenuedittip="' . JHtml::tooltipText('JLIB_HTML_EDIT_MENU_ITEM', 'JLIB_HTML_EDIT_MENU_ITEM_ID') . '"'
45+
:
46+
''
47+
),
48+
$moduleHtml,
49+
1,
50+
$count
51+
);
52+
53+
if ($count)
54+
{
55+
// Load once booststrap tooltip and add stylesheet and javascript to head:
56+
JHtml::_('bootstrap.loadCss', true, JFactory::getDocument()->getDirection());
57+
JHtml::_('bootstrap.tooltip');
58+
JHtml::_('bootstrap.popover');
59+
60+
JFactory::getDocument()->addStyleSheet('media/system/css/frontediting.css')
61+
->addScript('media/system/js/frontediting.js');
62+
}

libraries/joomla/document/html/renderer/modules.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,26 @@ public function render($position, $params = array(), $content = null)
3434
$renderer = $this->_doc->loadRenderer('module');
3535
$buffer = '';
3636

37+
$app = JFactory::getApplication();
38+
$frontediting = $app->get('frontediting', 1);
39+
$user = JFactory::getUser();
40+
41+
$canEdit = $user->id && $frontediting && !($app->isAdmin() && $frontediting < 2) && $user->authorise('core.edit', 'com_modules');
42+
$menusEditing = ($frontediting == 2) && $user->authorise('core.edit', 'com_menus');
43+
3744
foreach (JModuleHelper::getModules($position) as $mod)
3845
{
39-
$buffer .= $renderer->render($mod, $params, $content);
46+
$moduleHtml = $renderer->render($mod, $params, $content);
47+
48+
if ($canEdit && trim($moduleHtml) != '' && $user->authorise('core.edit', 'com_modules.module.' . $mod->id))
49+
{
50+
$displayData = array('moduleHtml' => &$moduleHtml, 'module' => $mod, 'position' => $position, 'menusediting' => $menusEditing);
51+
JLayoutHelper::render('joomla.edit.frontediting_modules', $displayData);
52+
}
53+
54+
$buffer .= $moduleHtml;
4055
}
56+
4157
return $buffer;
4258
}
4359
}

0 commit comments

Comments
 (0)