diff --git a/administrator/components/com_content/config.xml b/administrator/components/com_content/config.xml index 3cd59029f78..e9cbd77a9b7 100644 --- a/administrator/components/com_content/config.xml +++ b/administrator/components/com_content/config.xml @@ -441,6 +441,17 @@ + + + + + JNO + + + + +
diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index bc9bd82c046..343523b3358 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -469,6 +469,36 @@ public function getItem($pk = null) } } + // Expression to search for(id) + $regexmodid = '/{loadmoduleid\s([1-9][0-9]*)}/i'; + + // Find all instances of loadmoduleid and store it in $matchesmodid + preg_match_all($regexmodid, $item->articletext, $matchesmodid, PREG_SET_ORDER); + $importedModules = []; + + // If no matches, skip this + if ($matchesmodid) + { + foreach ($matchesmodid as $match) + { + $importedModules[] = $match[1]; + } + + $db = $this->getDbo(); + $query = $db->getQuery(true) + ->select( + [ + $db->quoteName('id'), + $db->quoteName('title'), + $db->quoteName('published'), + ] + ) + ->from($db->quoteName('#__modules')); + $query->where($db->quoteName('id') . 'IN (' . implode(',', $query->bindArray(array_values($importedModules))) . ')'); + + $item->importedModules = $db->setQuery($query)->loadObjectList(); + } + return $item; } diff --git a/administrator/components/com_content/tmpl/article/edit.php b/administrator/components/com_content/tmpl/article/edit.php index bf359a97e0f..dfff16d15e1 100644 --- a/administrator/components/com_content/tmpl/article/edit.php +++ b/administrator/components/com_content/tmpl/article/edit.php @@ -21,6 +21,29 @@ /** @var Joomla\CMS\WebAsset\WebAssetManager $wa */ $wa = $this->document->getWebAssetManager(); + +$wa->useScript('com_content.admin-article-edit'); + +// Set up the bootstrap modal that will be used for all module editors +echo HTMLHelper::_( + 'bootstrap.renderModal', + 'moduleEditModal', + array( + 'title' => Text::_('COM_CONTENT_HEADING_IMPORTED_MODULE_EDIT'), + 'backdrop' => 'static', + 'keyboard' => false, + 'closeButton' => false, + 'bodyHeight' => '70', + 'modalWidth' => '80', + 'footer' => '' + . '' + . '', + ) +); + $wa->getRegistry()->addExtensionRegistryFile('com_contenthistory'); $wa->useScript('keepalive') ->useScript('form.validate') @@ -104,6 +127,79 @@ + + get('show_imported_modules', 1) == 1 && !empty($this->item->importedModules)): ?> + +
+ + + + + + + + + + + + + + item->importedModules as $module) : ?> + + + + + + + + + +
+ +
+ + + + + + + + + +
+ escape($module->id); ?> + + escape($module->title); ?> + + published) : ?> + + + + + + + + + + + + +
+
+ + + get('show_article_options', 1) == 1) : ?> diff --git a/administrator/components/com_modules/tmpl/modules/modal.php b/administrator/components/com_modules/tmpl/modules/modal.php index 972919a7dd7..c805b9849da 100644 --- a/administrator/components/com_modules/tmpl/modules/modal.php +++ b/administrator/components/com_modules/tmpl/modules/modal.php @@ -36,6 +36,10 @@ } ?>
+ + + +
diff --git a/administrator/language/en-GB/com_content.ini b/administrator/language/en-GB/com_content.ini index 716d1c01a88..25966ff0429 100644 --- a/administrator/language/en-GB/com_content.ini +++ b/administrator/language/en-GB/com_content.ini @@ -32,6 +32,7 @@ COM_CONTENT_CREATE_ARTICLE_ERROR="When default category is enabled, a category s COM_CONTENT_CREATE_ARTICLE_REDIRECTMENU_DESC="Select the page the user will be redirected to after a successful article submission and after cancel (if not set differently below). The default is to redirect to the home page." COM_CONTENT_CREATE_ARTICLE_REDIRECTMENU_LABEL="Submission/Cancel Redirect" COM_CONTENT_DASHBOARD_TITLE="Content Dashboard" +COM_CONTENT_EDIT_MODULE="Edit" COM_CONTENT_EDIT_ARTICLE="Edit Article" COM_CONTENT_EDIT_CATEGORY="Edit Category" COM_CONTENT_EDITING_LAYOUT="Editing Layout" @@ -93,6 +94,7 @@ COM_CONTENT_FIELDS_ARTICLE_FIELD_ADD_TITLE="Articles: New Field" COM_CONTENT_FIELDS_ARTICLE_FIELD_EDIT_TITLE="Articles: Edit Field" COM_CONTENT_FIELDS_ARTICLE_FIELDS_TITLE="Articles: Fields" COM_CONTENT_FIELDS_TYPE_MODAL_ARTICLE="Article" +COM_CONTENT_FIELDSET_MODULES="Imported Modules" COM_CONTENT_FIELDSET_PUBLISHING="Publishing" COM_CONTENT_FIELDSET_RULES="Permissions" COM_CONTENT_FIELDSET_URLS_AND_IMAGES="Images and Links" @@ -107,9 +109,14 @@ COM_CONTENT_HEADING_DATE_CREATED="Date Created" COM_CONTENT_HEADING_DATE_MODIFIED="Date Modified" COM_CONTENT_HEADING_DATE_PUBLISH_DOWN="Finish Publishing" COM_CONTENT_HEADING_DATE_PUBLISH_UP="Start Publishing" +COM_CONTENT_HEADING_IMPORTED_MODULE_EDIT="Edit Module" +COM_CONTENT_HEADING_IMPORTED_MODULE_ID="ID" +COM_CONTENT_HEADING_IMPORTED_MODULE_REMOVE="Remove from Article" +COM_CONTENT_HEADING_IMPORTED_MODULE_TITLE="Title" COM_CONTENT_ID_LABEL="ID" COM_CONTENT_IMAGE_FULLTEXT_CLASS_LABEL="Full Text Image Class" COM_CONTENT_IMAGE_INTRO_CLASS_LABEL="Intro Image Class" +COM_CONTENT_IMPORTED_MODULES_TABLE_CAPTION="Table for Imported Modules" COM_CONTENT_MODIFIED_ASC="Date Modified ascending" COM_CONTENT_MODIFIED_DESC="Date Modified descending" COM_CONTENT_MONTH="Month" @@ -152,6 +159,7 @@ COM_CONTENT_PUBLISH_DOWN_DESC="Finish Publishing descending" COM_CONTENT_PUBLISH_UP_ASC="Start Publishing ascending" COM_CONTENT_PUBLISH_UP_DESC="Start Publishing descending" COM_CONTENT_PUBLISHED="Published" +COM_CONTENT_REMOVE_MODULE="Remove" COM_CONTENT_RUN_TRANSITIONS="Run Transitions" COM_CONTENT_SAVE_SUCCESS="Article saved." COM_CONTENT_SAVE_WARNING="Alias already existed so a number was added at the end. You can re-edit the article to customise the alias." @@ -164,6 +172,7 @@ COM_CONTENT_SHOW_ASSOCIATIONS_LABEL="Multilingual Associations" COM_CONTENT_SHOW_CONFIGURE_EDIT_LABEL="Edit Screen Options" COM_CONTENT_SHOW_IMAGES_URLS_BACK_LABEL="Administrator Images and Links" COM_CONTENT_SHOW_IMAGES_URLS_FRONT_LABEL="Frontend Images and Links" +COM_CONTENT_SHOW_IMPORTED_MODULES="Show Imported Modules" COM_CONTENT_SHOW_PERMISSIONS_LABEL="Article Permissions" COM_CONTENT_SHOW_PUBLISHING_OPTIONS_LABEL="Publishing Options" COM_CONTENT_SLIDER_EDITOR_CONFIG="Configure Edit Screen" diff --git a/build/media_source/com_content/joomla.asset.json b/build/media_source/com_content/joomla.asset.json index af995ea1c93..f7a96a92143 100644 --- a/build/media_source/com_content/joomla.asset.json +++ b/build/media_source/com_content/joomla.asset.json @@ -5,6 +5,30 @@ "description": "Joomla CMS", "license": "GPL-2.0-or-later", "assets": [ + { + "name": "com_content.admin-article-edit.es5", + "type": "script", + "uri": "com_content/admin-article-edit-es5.min.js", + "dependencies": [ + "core" + ], + "attributes": { + "nomodule": true, + "defer": true + } + }, + { + "name": "com_content.admin-article-edit", + "type": "script", + "uri": "com_content/admin-article-edit.min.js", + "dependencies": [ + "com_content.admin-article-edit.es5" + ], + "attributes": { + "type": "module", + "defer": true + } + }, { "name": "com_content.admin-article-pagebreak.es5", "type": "script", diff --git a/build/media_source/com_content/js/admin-article-edit.es6.js b/build/media_source/com_content/js/admin-article-edit.es6.js new file mode 100644 index 00000000000..9117083112d --- /dev/null +++ b/build/media_source/com_content/js/admin-article-edit.es6.js @@ -0,0 +1,66 @@ +/** + * @copyright (C) 2018 Open Source Matters, Inc. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ +(() => { + 'use strict'; + + /** + * Javascript to display the modal when user clicks on the + * module edit button. The modal is initialized by the id + * of the module found using data-module-id attribute of + * the button. + * */ + + document.addEventListener('DOMContentLoaded', () => { + const baseLink = 'index.php?option=com_modules&client_id=0&task=module.edit&tmpl=component&view=module&layout=modal&id='; + const modalBtnElements = [].slice.call(document.getElementsByClassName('module-edit-link')); + const elements = [].slice.call(document.querySelectorAll('#moduleEditModal .modal-footer .btn')); + const removeModBtnElements = [].slice.call(document.getElementsByClassName('module-remove-link')); + + if (modalBtnElements.length) { + modalBtnElements.forEach((linkElement) => { + linkElement.addEventListener('click', (_ref) => { + const { target } = _ref; + const link = baseLink + target.getAttribute('data-module-id'); + const modal = document.getElementById('moduleEditModal'); + const body = modal.querySelector('.modal-body'); + const iFrame = document.createElement('iframe'); + iFrame.src = link; + iFrame.setAttribute('class', 'class="iframe jviewport-height70"'); + body.innerHTML = ''; + body.appendChild(iFrame); + modal.open(); + }); + }); + } + + if (elements.length) { + elements.forEach((element) => { + element.addEventListener('click', (_ref2) => { + const { target } = _ref2; + const dataTarget = target.getAttribute('data-bs-target'); + + if (dataTarget) { + const iframe = document.querySelector('#moduleEditModal iframe'); + const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; + iframeDocument.querySelector(dataTarget).click(); + } + }); + }); + } + + if (removeModBtnElements.length) { + removeModBtnElements.forEach((linkElement) => { + linkElement.addEventListener('click', (_ref) => { + const { target } = _ref; + const moduleId = target.getAttribute('data-module-id'); + let editorText = Joomla.editors.instances.jform_articletext.getValue(); + editorText = editorText.replace(`{loadmoduleid ${moduleId}}`, ''); + Joomla.editors.instances.jform_articletext.setValue(editorText); + document.querySelector('.button-apply.btn.btn-success').click(); + }); + }); + } + }); +})();