Skip to content

Core Enhancement 2 -Incorporation of Modules in the Articles-Edit-View #8

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

Open
wants to merge 36 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
45782b0
init language files
YatharthVyas Jun 23, 2021
0da15bd
init xml form
YatharthVyas Jun 23, 2021
12d56a0
init plugin php file
YatharthVyas Jun 23, 2021
a6715a8
Merge branch 'feature-article-module' of https://github.com/YatharthV…
YatharthVyas Jun 23, 2021
431cb80
language constant for modules tab
YatharthVyas Jun 23, 2021
3105800
imported modules tab
YatharthVyas Jun 23, 2021
8c36d28
installation sql script
YatharthVyas Jun 24, 2021
27c23bf
add language constants
YatharthVyas Jun 25, 2021
3d8b9c6
show toolbar
YatharthVyas Jun 25, 2021
fdf301a
fetch all modules used in the article
YatharthVyas Jun 25, 2021
307300a
add new tab for imported modules
YatharthVyas Jun 25, 2021
8da56fe
add switcher for toggling the imported modules tab
YatharthVyas Jun 25, 2021
fde75fa
sort sql install script alphabetically
YatharthVyas Jun 29, 2021
822e539
add missing comma
YatharthVyas Jun 29, 2021
66f9691
edit modal script
YatharthVyas Jun 30, 2021
de3b3a9
add modal script to assets
YatharthVyas Jun 30, 2021
abbcee7
edit module modal
YatharthVyas Jun 30, 2021
e7a0cdd
Update administrator/components/com_content/tmpl/article/edit.php
YatharthVyas Jun 30, 2021
6b53d86
Change heading language constant
YatharthVyas Jun 30, 2021
31b3b10
Merge branch 'feature-article-module' of https://github.com/YatharthV…
YatharthVyas Jun 30, 2021
89ab339
js lint
YatharthVyas Jun 30, 2021
fe446f1
introduce apply button param for Saving
YatharthVyas Jul 1, 2021
dd61a88
Display a save button in the modal
YatharthVyas Jul 1, 2021
357da31
add remove id language constant
YatharthVyas Jul 2, 2021
de44fae
rename the js file name in assets
YatharthVyas Jul 2, 2021
ecfc63b
remove old js file
YatharthVyas Jul 2, 2021
c096b57
js script for modal and remove function
YatharthVyas Jul 2, 2021
92eac8b
add column for removing the module from article
YatharthVyas Jul 2, 2021
dcad97f
js lint
YatharthVyas Jul 2, 2021
0b7ad24
js lint
YatharthVyas Jul 2, 2021
45005fe
check imported modules for empty
YatharthVyas Jul 5, 2021
7c214e9
New Module button in select module modal
YatharthVyas Jul 8, 2021
ba7c8ef
correct the link
YatharthVyas Jul 8, 2021
f816ec9
revert newmodule xtd editor plugin files
YatharthVyas Jul 8, 2021
6a539b3
add newline at the end
YatharthVyas Jul 8, 2021
8744b8d
fix remove module js function
YatharthVyas Jul 12, 2021
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
11 changes: 11 additions & 0 deletions administrator/components/com_content/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,17 @@
<option value="1">JSHOW</option>
</field>

<field
name="show_imported_modules"
type="radio"
label="COM_CONTENT_SHOW_IMPORTED_MODULES"
layout="joomla.form.field.radio.switcher"
default="1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="spacer3"
type="spacer"
Expand Down
12 changes: 12 additions & 0 deletions administrator/components/com_content/forms/article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,18 @@
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="show_imported_modules"
type="list"
label="COM_CONTENT_SHOW_IMPORTED_MODULES"
useglobal="true"
default=""
validate="options"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>

<fieldset name="basic-limited" label="COM_CONTENT_ATTRIBS_FIELDSET_LABEL">
Expand Down
30 changes: 30 additions & 0 deletions administrator/components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
96 changes: 96 additions & 0 deletions administrator/components/com_content/tmpl/article/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" data-bs-target="#closeBtn">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>'
. '<button type="button" class="btn btn-primary" data-bs-dismiss="modal" data-bs-target="#saveBtn">'
. Text::_('JSAVE') . '</button>'
. '<button type="button" class="btn btn-success" data-bs-target="#applyBtn">'
. Text::_('JAPPLY') . '</button>',
)
);

$wa->getRegistry()->addExtensionRegistryFile('com_contenthistory');
$wa->useScript('keepalive')
->useScript('form.validate')
Expand Down Expand Up @@ -104,6 +127,79 @@
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php endif; ?>

<?php // Do not show the publishing options if the edit form is configured not to. ?>
<?php if ($params->get('show_imported_modules', 1) == 1 && !empty($this->item->importedModules)): ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'modules', Text::_('COM_CONTENT_FIELDSET_MODULES')); ?>
<fieldset id="fieldset-modules" class="options-form">
<legend><?php echo Text::_('COM_CONTENT_FIELDSET_MODULES'); ?></legend>
<table class="table" id="modules_assigned">
<caption class="visually-hidden">
<?php echo Text::_('COM_CONTENT_IMPORTED_MODULES_TABLE_CAPTION'); ?>
</caption>
<thead>
<tr>
<th scope="col" class="w-10">
<?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_MODULE_ID'); ?>
</th>
<th scope="col">
<?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_MODULE_TITLE'); ?>
</th>
<th scope="col" class="w-10">
<?php echo Text::_('JPUBLISHED'); ?>
</th>
<th scope="col" class="w-15">
<?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_MODULE_EDIT'); ?>
</th>
<th scope="col" class="w-15">
<?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_MODULE_REMOVE'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->item->importedModules as $module) : ?>
<tr id="tr-<?php echo $module->id; ?>" class="<?php echo $no; ?><?php echo $status; ?>row<?php echo $module->id % 2; ?>">
<td id="mod-<?php echo $module->id; ?>">
<?php echo $this->escape($module->id); ?>
</td>
<td id="mod-<?php echo $module->title; ?>">
<?php echo $this->escape($module->title); ?>
</td>
<td id="mod-<?php echo $module->published; ?>">
<?php if ($module->published) : ?>
<span class="badge bg-success">
<?php echo Text::_('JYES'); ?>
</span>
<?php else : ?>
<span class="badge bg-danger">
<?php echo Text::_('JNO'); ?>
</span>
<?php endif; ?>
</td>
<td id="status-<?php echo $module->id; ?>">
<button type="button"
data-bs-target="#moduleEditModal"
class="btn btn-link module-edit-link"
title="<?php echo Text::_('COM_CONTENT_EDIT_MODULE'); ?>"
id="title-<?php echo $module->id; ?>"
data-module-id="<?php echo $module->id; ?>">
<?php echo Text::_('COM_CONTENT_EDIT_MODULE'); ?>
</button>
</td>
<td id="status-<?php echo $module->id; ?>">
<button type="button"
class="btn btn-link module-remove-link"
data-module-id="<?php echo $module->id; ?>">
<?php echo Text::_('COM_CONTENT_REMOVE_MODULE'); ?>
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</fieldset>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php endif; ?>

<?php if ($params->get('show_article_options', 1) == 1) : ?>
<?php echo LayoutHelper::render('joomla.edit.params', $this); ?>
<?php endif; ?>
Expand Down
4 changes: 4 additions & 0 deletions administrator/components/com_modules/tmpl/modules/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
}
?>
<div class="container-popup">
<a class="button-new btn btn-success" href='index.php?option=com_modules&view=select&tmpl=component&client_id=0'>
<span class="icon-new" aria-hidden="true"></span>
<?php echo Text::_('JTOOLBAR_NEW'); ?>
</a>

<form action="<?php echo Route::_($link); ?>" method="post" name="adminForm" id="adminForm">

Expand Down
9 changes: 9 additions & 0 deletions administrator/language/en-GB/com_content.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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."
Expand All @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions build/media_source/com_content/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
66 changes: 66 additions & 0 deletions build/media_source/com_content/js/admin-article-edit.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @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();
});
});
}
});
})();