- md5
- 33d88c09075a13b6f74218fcfe502ef6
- sha1
- ad8a782eafce91da3b4b4fa8262c4d2b87b7ecf9
- sha256
- 139509d02afe5bdab2d3879fd13d402d193055de45b433ceb070250bb40677ee
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Content\Administrator\Helper;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Category;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
/**
* Content component helper.
*
* @since 1.6
*/
class ContentHelper extends \Joomla\CMS\Helper\ContentHelper
{
/**
* Check if state can be deleted
*
* @param int $id Id of state to delete
*
* @return boolean
*
* @since 4.0.0
*/
public static function canDeleteState(int $id): bool
{
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('id')
->from($db->quoteName('#__content'))
->where($db->quoteName('state') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER);
$db->setQuery($query);
$states = $db->loadResult();
return empty($states);
}
/**
* Method to filter transitions by given id of state
*
* @param array $transitions Array of transitions
* @param int $pk Id of state
* @param int $workflow_id Id of the workflow
*
* @return array
*
* @since 4.0.0
*/
public static function filterTransitions(array $transitions, int $pk, int $workflow_id = 0): array
{
return array_values(
array_filter(
$transitions,
function ($var) use ($pk, $workflow_id)
{
return in_array($var['from_stage_id'], [-1, $pk]) && $workflow_id == $var['workflow_id'];
}
)
);
}
/**
* Prepares a form
*
* @param Form $form The form to change
* @param array|object $data The form data
*
* @return void
*/
public static function onPrepareForm(Form $form, $data)
{
if ($form->getName() != 'com_categories.categorycom_content')
{
return;
}
$db = Factory::getDbo();
$data = (array) $data;
// Make workflows translateable
Factory::getLanguage()->load('com_workflow', JPATH_ADMINISTRATOR);
$form->setFieldAttribute('workflow_id', 'default', 'inherit');
$query = $db->getQuery(true);
$query->select($db->quoteName('title'))
->from($db->quoteName('#__workflows'))
->where(
[
$db->quoteName('default') . ' = 1',
$db->quoteName('published') . ' = 1',
]
);
$defaulttitle = $db->setQuery($query)->loadResult();
$option = Text::_('COM_WORKFLOW_INHERIT_WORKFLOW_NEW');
if (!empty($data['id']))
{
$category = new Category($db);
$categories = $category->getPath((int) $data['id']);
// Remove the current category, because we search for inheritance from parent.
array_pop($categories);
$option = Text::sprintf('COM_WORKFLOW_INHERIT_WORKFLOW', Text::_($defaulttitle));
if (!empty($categories))
{
$categories = array_reverse($categories);
$query = $db->getQuery(true);
$query->select($db->quoteName('title'))
->from($db->quoteName('#__workflows'))
->where(
[
$db->quoteName('id') . ' = :workflowId',
$db->quoteName('published') . ' = 1',
]
)
->bind(':workflowId', $workflow_id, ParameterType::INTEGER);
$db->setQuery($query);
foreach ($categories as $cat)
{
$cat->params = new Registry($cat->params);
$workflow_id = $cat->params->get('workflow_id');
if ($workflow_id == 'inherit')
{
continue;
}
elseif ($workflow_id == 'use_default')
{
break;
}
elseif ($workflow_id = (int) $workflow_id)
{
$title = $db->loadResult();
if (!is_null($title))
{
$option = Text::sprintf('COM_WORKFLOW_INHERIT_WORKFLOW', Text::_($title));
break;
}
}
}
}
}
$field = $form->getField('workflow_id', 'params');
$field->addOption($option, ['value' => 'inherit']);
$field->addOption(Text::sprintf('COM_WORKFLOW_USE_DEFAULT_WORKFLOW', Text::_($defaulttitle)), ['value' => 'use_default']);
$field->addOption('- ' . Text::_('COM_CONTENT_WORKFLOWS') . ' -', ['disabled' => 'true']);
}
}
The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.