Skip to content

Commit

Permalink
Merge branch '5.2-dev' into replace-empt-trash-in-listviews
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeutz authored Jul 31, 2024
2 parents e66327e + ab8d4ff commit 2d385a2
Show file tree
Hide file tree
Showing 28 changed files with 829 additions and 111 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

$config = new PhpCsFixer\Config();
$config
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRiskyAllowed(true)
->setHideProgress(false)
->setUsingCache(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function edit($key = null, $urlVar = null)
return false;
}

return parent::display();
return $this->display();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function __construct($config = [], MVCFactoryInterface $factory = null, C
if (empty($this->extension)) {
$this->extension = $this->input->get('extension', 'com_content');
}

$this->registerTask('save2menulist', 'save');
$this->registerTask('save2menublog', 'save');
}

/**
Expand Down Expand Up @@ -254,8 +257,34 @@ protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
$item->metadata = (string) $registry;
}

// When editing in modal then redirect to modalreturn layout
if ($this->input->get('layout') === 'modal' && $this->task === 'save') {
if (\in_array($this->getTask(), ['save2menulist', 'save2menublog'])) {
$editState = [];

$type = 'component';
$id = $model->getState('category.id');
$link = 'index.php?option=com_content&view=category';

if ($this->getTask() === 'save2menublog') {
$link .= '&layout=blog'; // Append the layout parameter for the blog layout
}

$editState = [
'id' => $id,
'link' => $link,
'title' => $model->getItem($id)->title,
'type' => $type,
'request' => ['id' => $id],
];

$this->app->setUserState('com_menus.edit.item', [
'data' => $editState,
'type' => $type,
'link' => $link,
]);

$this->setRedirect(Route::_('index.php?option=com_menus&view=item&client_id=0&menutype=mainmenu&layout=edit', false));
} elseif ($this->input->get('layout') === 'modal' && $this->task === 'save') {
// When editing in modal then redirect to modalreturn layout
$id = $item->id;
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
. '&layout=modalreturn&from-task=save';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function display($tpl = null)
protected function addToolbar()
{
$extension = Factory::getApplication()->getInput()->get('extension');

$user = $this->getCurrentUser();
$userId = $user->id;
$toolbar = Toolbar::getInstance();
Expand Down Expand Up @@ -203,9 +204,14 @@ protected function addToolbar()
$saveGroup = $toolbar->dropdownButton('save-group');

$saveGroup->configure(
function (Toolbar $childBar) {
function (Toolbar $childBar) use ($canDo, $component) {
$childBar->save('category.save');
$childBar->save2new('category.save2new');

if ($canDo->get('core.create', 'com_menus.menu') && $component === 'com_content') {
$childBar->save('category.save2menulist', 'JTOOLBAR_SAVE_TO_MENU_AS_LIST');
$childBar->save('category.save2menublog', 'JTOOLBAR_SAVE_TO_MENU_AS_BLOG');
}
}
);

Expand All @@ -223,7 +229,7 @@ function (Toolbar $childBar) {
$saveGroup = $toolbar->dropdownButton('save-group');

$saveGroup->configure(
function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable) {
function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable, $component) {
// Can't save the record if it's checked out and editable
if (!$checkedOut && $itemEditable) {
$childBar->save('category.save');
Expand All @@ -233,6 +239,11 @@ function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable) {
}
}

if ($canDo->get('core.create', 'com_menus.menu') && $component === 'com_content') {
$childBar->save('category.save2menulist', 'JTOOLBAR_SAVE_TO_MENU_AS_LIST');
$childBar->save('category.save2menublog', 'JTOOLBAR_SAVE_TO_MENU_AS_BLOG');
}

// If an existing item, can save to a copy.
if ($canDo->get('core.create')) {
$childBar->save2copy('category.save2copy');
Expand Down
34 changes: 33 additions & 1 deletion administrator/components/com_mails/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<inlinehelp button="show"/>
<fieldset
name="mails_options"
label="COM_MAILS_CONFIG_MAIL_OPTIONS" >
label="COM_MAILS_CONFIG_MAIL_OPTIONS"
addfieldprefix="Joomla\Component\Mails\Administrator\Field">

<field
name="mail_style"
Expand Down Expand Up @@ -49,6 +50,37 @@
exclude="administrator|api|cache|cli|components|includes|language|layouts|libraries|modules|plugins|templates|tmp"
/>

<field
name="disable_htmllayout"
type="radio"
label="COM_CONFIG_FIELD_MAILTEMPLATE_LAYOUT_OFF_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
showon="mail_style:html[OR]mail_style:both"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>

<field
name="mail_htmllayout"
type="mailtemplateLayout"
label="COM_CONFIG_FIELD_MAILTEMPLATE_LAYOUT_LABEL"
class="form-select"
showon="mail_style:html[OR]mail_style:both[AND]disable_htmllayout:1"
/>

<field
name="mail_logofile"
type="media"
label="COM_CONFIG_FIELD_MAILTEMPLATE_LOGOFILE_LABEL"
schemes="http,https,ftp,ftps,data,file"
validate="url"
relative="true"
default=""
showon="mail_style:html[OR]mail_style:both[AND]disable_htmllayout:1"
/>

</fieldset>

<fieldset
Expand Down
38 changes: 37 additions & 1 deletion administrator/components/com_mails/forms/template.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<form addfieldprefix="Joomla\Component\Mails\Administrator\Field">
<fieldset>
<field
name="template_id"
Expand Down Expand Up @@ -205,6 +205,42 @@
default=""
filter="string"
/>

<field
name="disable_htmllayout"
type="list"
label="COM_MAILS_FIELD_HTML_LAYOUT_OFF_LABEL"
validate="options"
class="form-select-color-state"
useglobal="true"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>

<field
name="htmllayout"
type="mailtemplateLayout"
label="COM_MAILS_FIELD_HTML_LAYOUT_LABEL"
class="form-select"
useglobal="true"
default=""
showon="disable_htmllayout!:0"
/>

<field
name="disable_logofile"
type="radio"
label="COM_MAILS_FIELD_HTML_LAYOUT_LOGO_OFF_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
showon="disable_htmllayout!:0[AND]htmllayout!:mailtemplate"
validate="options"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>

</fieldset>
</fields>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_mails
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Mails\Administrator\Field;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Form Field to display a list of the layouts for a field from
* the extension or template overrides.
*
* @since __DEPLOY_VERSION__
*/
class MailtemplateLayoutField extends FormField
{
/**
* The form field type.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $type = 'MailtemplateLayout';

/**
* Method to get the field input for a field layout field.
*
* @return string The field input.
*
* @since __DEPLOY_VERSION__
*/
protected function getInput()
{
$lang = Factory::getApplication()->getLanguage();

// Get the database object and a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);

// Build the query.
$query->select('element, name')
->from('#__extensions')
->where($db->quoteName('client_id') . ' = 0')
->where($db->quoteName('type') . ' = ' . $db->quote('template'))
->where($db->quoteName('enabled') . ' = 1');

// Set the query and load the templates.
$db->setQuery($query);
$templates = $db->loadObjectList('element');

// Prepare the grouped list
$groups = [];

// Add "Use Default"
$groups[]['items'][] = HTMLHelper::_('select.option', 'mailtemplate', Text::_('JOPTION_USE_DEFAULT'));

// Add a Use Global option if useglobal="true" in XML file
if ((string) $this->element['useglobal'] === 'true') {
$groups[Text::_('JOPTION_FROM_STANDARD')]['items'][] = HTMLHelper::_('select.option', '', Text::_('JGLOBAL_USE_GLOBAL'));
}

// Loop on all templates
if ($templates) {
foreach ($templates as $template) {
$files = [];
$template_paths = [
Path::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/joomla/mail'),
Path::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/com_mails/joomla/mail'),
];

// Add the layout options from the template paths.
foreach ($template_paths as $template_path) {
if (is_dir($template_path)) {
$files = array_merge($files, Folder::files($template_path, '^[^_]*\.php$', false, true));
}
}

if (\count($files)) {
// Create the group for the template
$groups[$template->name] = [];
$groups[$template->name]['id'] = $this->id . '_' . $template->element;
$groups[$template->name]['text'] = Text::sprintf('JOPTION_FROM_TEMPLATE', $template->name);
$groups[$template->name]['items'] = [];

foreach ($files as $file) {
// Add an option to the template group
$value = basename($file, '.php');
$text = $lang->hasKey($key = strtoupper('TPL_' . $template->element . '_MAILTEMPLATE_LAYOUT_' . $value))
? Text::_($key) : $value;
$groups[$template->name]['items'][] = HTMLHelper::_('select.option', $template->element . ':' . $value, $text);
}
}
}
}

// Compute attributes for the grouped list
$attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';

// Prepare HTML code
$html = [];

// Compute the current selected values
$selected = [$this->value];

// Add a grouped list
$html[] = HTMLHelper::_(
'select.groupedlist',
$groups,
$this->name,
['id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected]
);

return implode($html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function getForm($data = [], $loadData = true)

if ($params->get('mail_style', 'plaintext') == 'plaintext') {
$form->removeField('htmlbody');
$form->removeField('disable_htmllayout', 'params');
$form->removeField('htmllayout', 'params');
$form->removeField('disable_logofile', 'params');
}

if ($params->get('mail_style', 'plaintext') == 'html') {
Expand All @@ -106,6 +109,9 @@ public function getForm($data = [], $loadData = true)
$form->removeField('smtpauth', 'params');
$form->removeField('smtpuser', 'params');
$form->removeField('smtppass', 'params');
$form->removeField('disable_htmllayout', 'params');
$form->removeField('htmllayout', 'params');
$form->removeField('disable_logofile', 'params');
}

if (!$params->get('copy_mails')) {
Expand Down
14 changes: 4 additions & 10 deletions administrator/components/com_mails/src/View/Template/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,11 @@ protected function addToolbar()
'pencil-2 article-add'
);

$saveGroup = $toolbar->dropdownButton('save-group');

$saveGroup->configure(
function (Toolbar $childBar) {
$childBar->apply('template.apply');
$childBar->save('template.save');
}
);

$toolbar->apply('template.apply');
$toolbar->divider();
$toolbar->save('template.save');
$toolbar->divider();
$toolbar->cancel('template.cancel', 'JTOOLBAR_CLOSE');

$toolbar->divider();
$toolbar->help('Mail_Template:_Edit');
}
Expand Down
Loading

0 comments on commit 2d385a2

Please sign in to comment.