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

[5.3] [GSoC 21] Core Enhancement 2 - Incorporation of Modules in Articles-Edit-View #34764

Draft
wants to merge 75 commits into
base: 5.3-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
75 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
a6ac050
Update signature
bembelimen 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
289321d
Merge branch 'feature-article-module' of https://github.com/YatharthV…
YatharthVyas Jul 12, 2021
4f45b86
find imported positions and style
YatharthVyas Jul 13, 2021
3e4c449
show imported positions in imported modules tab
YatharthVyas Jul 13, 2021
a05208a
function to remove imported positions
YatharthVyas Jul 13, 2021
bea22bb
remove unused var
YatharthVyas Jul 14, 2021
c55cdd0
add id to the btn and fix the URL
YatharthVyas Jul 14, 2021
8d53835
script to save the importOnSave cookie
YatharthVyas Jul 14, 2021
f5fabb7
delete the cookie and import module on modal close
YatharthVyas Jul 14, 2021
558f6c6
hide Save and Close btn for import module modal
YatharthVyas Jul 14, 2021
dd92444
use iframe location href instead of src
YatharthVyas Jul 14, 2021
d7c01f7
update copyright year
YatharthVyas Jul 15, 2021
653bd70
fix indentation
YatharthVyas Jul 15, 2021
52416a5
new language constants
YatharthVyas Jul 17, 2021
dfbe15f
generalize remove func for position and loadmodule
YatharthVyas Jul 17, 2021
7db20c1
look for modules imported by loadmodule
YatharthVyas Jul 17, 2021
2de832b
display modules imported by loadmodule
YatharthVyas Jul 17, 2021
bd03514
phpcs
YatharthVyas Jul 17, 2021
a0176a4
Update administrator/components/com_content/src/Model/ArticleModel.php
YatharthVyas Jul 18, 2021
422123f
Update administrator/components/com_content/src/Model/ArticleModel.php
YatharthVyas Jul 18, 2021
7f43a9b
Update administrator/components/com_content/src/Model/ArticleModel.php
YatharthVyas Jul 18, 2021
1db305d
Update article.xml
YatharthVyas Aug 6, 2021
192ad10
fix formatting for multiline comments
YatharthVyas Aug 20, 2021
4261d5d
format multiline comment
YatharthVyas Aug 20, 2021
389180c
Merge branch 'feature-article-module' of https://github.com/YatharthV…
YatharthVyas Aug 20, 2021
b551737
fix indent of multiline comment
YatharthVyas Aug 20, 2021
dea0a39
s/clsoed/closed
YatharthVyas Jan 8, 2022
3aad473
Merge branch '4.1-dev' into feature-article-module
YatharthVyas Jan 8, 2022
2fae00a
remove unused variable
YatharthVyas Jan 8, 2022
18b0dba
lint
YatharthVyas Jan 8, 2022
8b9d12e
Merge tag 'psr12anchor' into psr12/merge/34764
joomla-bot Jun 27, 2022
7fd4b12
Phase 1 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
d9eb5f8
Phase 2 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
9a8a133
Merge tag 'psr12final' into psr12/merge/34764
joomla-bot Jun 27, 2022
d06ca56
Merge branch '4.2-dev' into feature-article-module
chmst Oct 23, 2022
d9d7ac1
Merge branch '5.1-dev' into feature-article-module
wilsonge Nov 22, 2023
d1562bd
Merge branch '5.1-dev' into feature-article-module
LadySolveig Jan 10, 2024
8de72b5
Merge branch '5.2-dev' into feature-article-module
obuisard Jul 27, 2024
edf53e8
Merge branch '5.3-dev' into feature-article-module
LadySolveig Oct 7, 2024
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
13 changes: 13 additions & 0 deletions administrator/components/com_content/forms/article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>

</fieldset>

<fieldset name="category" label="JCATEGORY">
Expand Down Expand Up @@ -612,6 +613,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
91 changes: 91 additions & 0 deletions administrator/components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormFactoryInterface;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper;
Expand Down Expand Up @@ -469,6 +470,96 @@ public function getItem($pk = null)
}
}

// Expression to search for (positions)
$regex = '/{loadposition\s(.*?)}/i';

// Expression to search for (modules)
$regexmod = '/{loadmodule\s(.*?)}/i';

// Expression to search for (id)
$regexmodid = '/{loadmoduleid\s([1-9][0-9]*)}/i';

/**
* Find all instances of plugin and put in $matches for loadposition
* $matches[0] is full pattern match, $matches[1] is the position
*/
preg_match_all($regex, $item->articletext, $matches, PREG_SET_ORDER);
$item->importedPositions = [];

// No matches, skip this
if ($matches)
{
foreach ($matches as $match)
{
$matcheslist = explode(',', $match[1]);

$position = trim($matcheslist[0]);
$style = array_key_exists(1, $matcheslist) ? trim($matcheslist[1]) : 'none';

$item->importedPositions[] = array('name' => $position, 'style' => $style, 'editorText' => $match[0]);
}
}

// Find all instances of plugin and put in $matchesmod for loadmodule
preg_match_all($regexmod, $item->articletext, $matchesmod, PREG_SET_ORDER);

// If no matches, skip this
if ($matchesmod)
{
foreach ($matchesmod as $matchmod)
{
$matchesmodlist = explode(',', $matchmod[1]);

$module = trim($matchesmodlist[0]);
$name = array_key_exists(1, $matchesmodlist) ? htmlspecialchars_decode(trim($matchesmodlist[1])) : null;
$stylemod = array_key_exists(2, $matchesmodlist) ? trim($matchesmodlist[2]) : 'none';
YatharthVyas marked this conversation as resolved.
Show resolved Hide resolved

$mod = ModuleHelper::getModule($module, $name);

/**
* If the module without the mod_ isn't found, try it with mod_.
* This allows people to enter it either way in the content
*/
if (!isset($mod))
{
$mod = ModuleHelper::getModule('mod_' . $module, $name);
}

if (isset($mod))
{
$mod->editorText = $matchmod[0];
$item->importedModuleTypes[] = $mod;
}
}
}

// 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
202 changes: 202 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,185 @@
<?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) || !empty($this->item->importedPositions))): ?>
<?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>

<?php if (!empty($this->item->importedModules)) : ?>
<h3> <?php echo Text::_('COM_CONTENT_FIELDSET_MODULES'); ?> </h3>
<table class="table mb-4" 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_REMOVE'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->item->importedModules as $module) : ?>
<tr id="tr-<?php echo $module->id; ?>" class="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_FROM_ARTICLE'); ?>
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

<?php if (!empty($this->item->importedModuleTypes)) : ?>
<h3> <?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_MODULE_TYPES'); ?> </h3>
<table class="table mb-4" 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_TYPE'); ?>
</th>
<th scope="col" class="w-20">
<?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_MODULE_TITLE'); ?>
</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_REMOVE'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->item->importedModuleTypes as $module) : ?>
<tr>
<td>
<?php echo $this->escape($module->id); ?>
</td>
<td>
<?php echo $this->escape($module->module); ?>
</td>
<td>
<?php echo $this->escape($module->title); ?>
</td>
<td>
<?php if (!empty($module->id)) : ?>
<button type="button"
data-bs-target="#moduleEditModal"
class="btn btn-link module-edit-link"
title="<?php echo Text::_('COM_CONTENT_EDIT_MODULE'); ?>"
data-module-id="<?php echo $module->id; ?>">
<?php echo Text::_('COM_CONTENT_EDIT_MODULE'); ?>
</button>
<?php endif; ?>
</td>
<td>
<button type="button"
class="btn btn-link import-remove-link"
data-importText="<?php echo $module->editorText; ?>">
<?php echo Text::_('COM_CONTENT_REMOVE_FROM_ARTICLE'); ?>
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

<?php if (!empty($this->item->importedPositions)) : ?>
<h3> <?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_POSITION'); ?> </h3>
<table class="table" id="positions_assigned">
<caption class="visually-hidden">
<?php echo Text::_('COM_CONTENT_IMPORTED_POSITIONS_TABLE_CAPTION'); ?>
</caption>
<thead>
<tr>
<th scope="col">
<?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_POSITION_NAME'); ?>
</th>
<th scope="col" class="w-15">
<?php echo Text::_('COM_CONTENT_HEADING_IMPORTED_POSITION_STYLE'); ?>
</th>
<th scope="col" class="w-15">
<?php echo Text::_('COM_CONTENT_HEADING_REMOVE'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->item->importedPositions as $position) : ?>
<tr>
<td>
<?php echo $this->escape($position["name"]); ?>
</td>
<td>
<?php echo $this->escape($position["style"]); ?>
</td>
<td>
<button type="button"
class="btn btn-link import-remove-link"
data-importText="<?php echo $position["editorText"]; ?>">
<?php echo Text::_('COM_CONTENT_REMOVE_FROM_ARTICLE'); ?>
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</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
18 changes: 11 additions & 7 deletions administrator/components/com_modules/src/View/Module/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ protected function addToolbar()
{
ToolbarHelper::apply('module.apply');

ToolbarHelper::saveGroup(
[
['save', 'module.save'],
['save2new', 'module.save2new']
],
'btn-success'
);
// Hide the Save and Close button for com_content Import Module Modal flow.
if (!Factory::getApplication()->input->cookie->get('com_modules_importOnSave'))
{
ToolbarHelper::saveGroup(
[
['save', 'module.save'],
['save2new', 'module.save2new']
],
'btn-success'
);
}

ToolbarHelper::cancel('module.cancel');
}
Expand Down
Loading