[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Plugin 4 * @subpackage Fields.Media 5 * 6 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 defined('_JEXEC') or die; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\Form\Form; 14 15 /** 16 * Fields Media Plugin 17 * 18 * @since 3.7.0 19 */ 20 class PlgFieldsMedia extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin 21 { 22 /** 23 * Transforms the field into a DOM XML element and appends it as a child on the given parent. 24 * 25 * @param stdClass $field The field. 26 * @param DOMElement $parent The field node parent. 27 * @param Form $form The form. 28 * 29 * @return DOMElement 30 * 31 * @since 4.0.0 32 */ 33 public function onCustomFieldsPrepareDom($field, DOMElement $parent, Form $form) 34 { 35 $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); 36 37 if (!$fieldNode) 38 { 39 return $fieldNode; 40 } 41 42 $fieldNode->setAttribute('type', 'accessiblemedia'); 43 44 if (Factory::getApplication()->getIdentity()->authorise('core.create', 'com_media')) 45 { 46 $fieldNode->setAttribute('disabled', 'false'); 47 } 48 49 return $fieldNode; 50 } 51 52 /** 53 * Before prepares the field value. 54 * 55 * @param string $context The context. 56 * @param \stdclass $item The item. 57 * @param \stdclass $field The field. 58 * 59 * @return void 60 * 61 * @since 4.0.0 62 */ 63 public function onCustomFieldsBeforePrepareField($context, $item, $field) 64 { 65 // Check if the field should be processed by us 66 if (!$this->isTypeSupported($field->type)) 67 { 68 return; 69 } 70 71 // Check if the field value is an old (string) value 72 $field->value = $this->checkValue($field->value); 73 } 74 75 /** 76 * Before prepares the field value. 77 * 78 * @param string $value The value to check. 79 * 80 * @return array The checked value 81 * 82 * @since 4.0.0 83 */ 84 private function checkValue($value) 85 { 86 json_decode($value); 87 88 if (json_last_error() === JSON_ERROR_NONE) 89 { 90 return (array) json_decode($value, true); 91 } 92 93 return array('imagefile' => $value, 'alt_text' => ''); 94 } 95 }
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 |