[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_content 6 * 7 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Content\Administrator\Helper; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Form\Form; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Table\Category; 17 use Joomla\CMS\Workflow\WorkflowServiceInterface; 18 use Joomla\Database\ParameterType; 19 use Joomla\Registry\Registry; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * Content component helper. 27 * 28 * @since 1.6 29 */ 30 class ContentHelper extends \Joomla\CMS\Helper\ContentHelper 31 { 32 /** 33 * Check if state can be deleted 34 * 35 * @param int $id Id of state to delete 36 * 37 * @return boolean 38 * 39 * @since 4.0.0 40 */ 41 public static function canDeleteState(int $id): bool 42 { 43 $db = Factory::getDbo(); 44 $query = $db->getQuery(true); 45 46 $query->select('id') 47 ->from($db->quoteName('#__content')) 48 ->where($db->quoteName('state') . ' = :id') 49 ->bind(':id', $id, ParameterType::INTEGER); 50 $db->setQuery($query); 51 $states = $db->loadResult(); 52 53 return empty($states); 54 } 55 56 /** 57 * Method to filter transitions by given id of state 58 * 59 * @param array $transitions Array of transitions 60 * @param int $pk Id of state 61 * @param int $workflowId Id of the workflow 62 * 63 * @return array 64 * 65 * @since 4.0.0 66 */ 67 public static function filterTransitions(array $transitions, int $pk, int $workflowId = 0): array 68 { 69 return array_values( 70 array_filter( 71 $transitions, 72 function ($var) use ($pk, $workflowId) { 73 return in_array($var['from_stage_id'], [-1, $pk]) && $workflowId == $var['workflow_id']; 74 } 75 ) 76 ); 77 } 78 79 /** 80 * Prepares a form 81 * 82 * @param Form $form The form to change 83 * @param array|object $data The form data 84 * 85 * @return void 86 */ 87 public static function onPrepareForm(Form $form, $data) 88 { 89 if ($form->getName() != 'com_categories.categorycom_content') { 90 return; 91 } 92 93 $db = Factory::getDbo(); 94 95 $data = (array) $data; 96 97 // Make workflows translatable 98 Factory::getLanguage()->load('com_workflow', JPATH_ADMINISTRATOR); 99 100 $form->setFieldAttribute('workflow_id', 'default', 'inherit'); 101 102 $component = Factory::getApplication()->bootComponent('com_content'); 103 104 if ( 105 !$component instanceof WorkflowServiceInterface 106 || !$component->isWorkflowActive('com_content.article') 107 ) { 108 $form->removeField('workflow_id', 'params'); 109 110 return; 111 } 112 113 $query = $db->getQuery(true); 114 115 $query->select($db->quoteName('title')) 116 ->from($db->quoteName('#__workflows')) 117 ->where( 118 [ 119 $db->quoteName('default') . ' = 1', 120 $db->quoteName('published') . ' = 1', 121 $db->quoteName('extension') . ' = ' . $db->quote('com_content.article'), 122 ] 123 ); 124 125 $defaulttitle = $db->setQuery($query)->loadResult(); 126 127 $option = Text::_('COM_WORKFLOW_INHERIT_WORKFLOW_NEW'); 128 129 if (!empty($data['id'])) { 130 $category = new Category($db); 131 132 $categories = $category->getPath((int) $data['id']); 133 134 // Remove the current category, because we search for inheritance from parent. 135 array_pop($categories); 136 137 $option = Text::sprintf('COM_WORKFLOW_INHERIT_WORKFLOW', Text::_($defaulttitle)); 138 139 if (!empty($categories)) { 140 $categories = array_reverse($categories); 141 142 $query = $db->getQuery(true); 143 144 $query->select($db->quoteName('title')) 145 ->from($db->quoteName('#__workflows')) 146 ->where( 147 [ 148 $db->quoteName('id') . ' = :workflowId', 149 $db->quoteName('published') . ' = 1', 150 $db->quoteName('extension') . ' = ' . $db->quote('com_content.article'), 151 ] 152 ) 153 ->bind(':workflowId', $workflow_id, ParameterType::INTEGER); 154 155 $db->setQuery($query); 156 157 foreach ($categories as $cat) { 158 $cat->params = new Registry($cat->params); 159 160 $workflow_id = $cat->params->get('workflow_id'); 161 162 if ($workflow_id == 'inherit') { 163 continue; 164 } elseif ($workflow_id == 'use_default') { 165 break; 166 } elseif ($workflow_id = (int) $workflow_id) { 167 $title = $db->loadResult(); 168 169 if (!is_null($title)) { 170 $option = Text::sprintf('COM_WORKFLOW_INHERIT_WORKFLOW', Text::_($title)); 171 172 break; 173 } 174 } 175 } 176 } 177 } 178 179 $field = $form->getField('workflow_id', 'params'); 180 181 $field->addOption($option, ['value' => 'inherit']); 182 183 $field->addOption(Text::sprintf('COM_WORKFLOW_USE_DEFAULT_WORKFLOW', Text::_($defaulttitle)), ['value' => 'use_default']); 184 185 $field->addOption('- ' . Text::_('COM_CONTENT_WORKFLOWS') . ' -', ['disabled' => 'true']); 186 } 187 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |