* @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Component\Associations\Administrator\Field\Modal; use Joomla\CMS\Factory; use Joomla\CMS\Form\FormField; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Session\Session; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Supports a modal item picker. * * @since 3.7.0 */ class AssociationField extends FormField { /** * The form field type. * * @var string * @since 3.7.0 */ protected $type = 'Modal_Association'; /** * Method to get the field input markup. * * @return string The field input markup. * * @since 3.7.0 */ protected function getInput() { // @todo USE Layouts here!!! // The active item id field. $value = (int) $this->value ?: ''; $doc = Factory::getApplication()->getDocument(); $wa = $doc->getWebAssetManager(); $doc->addScriptOptions('admin_associations_modal', ['itemId' => $value]); $wa->useScript('com_associations.admin-associations-modal'); // Setup variables for display. $html = array(); $linkAssociations = 'index.php?option=com_associations&view=associations&layout=modal&tmpl=component' . '&forcedItemType=' . Factory::getApplication()->input->get('itemtype', '', 'string') . '&function=jSelectAssociation_' . $this->id; $linkAssociations .= "&forcedLanguage=' + document.getElementById('target-association').getAttribute('data-language') + '"; $urlSelect = $linkAssociations . '&' . Session::getFormToken() . '=1'; // Select custom association button $html[] = '' . ' ' . '' . ''; // Clear association button $html[] = '' . ' ' . Text::_('JCLEAR') . ''; $html[] = ''; // Select custom association modal $html[] = HTMLHelper::_( 'bootstrap.renderModal', 'associationSelect' . $this->id . 'Modal', array( 'title' => Text::_('COM_ASSOCIATIONS_SELECT_TARGET'), 'backdrop' => 'static', 'url' => $urlSelect, 'height' => '400px', 'width' => '800px', 'bodyHeight' => 70, 'modalWidth' => 80, 'footer' => '', ) ); return implode("\n", $html); } }