element['new'] == 'true'); $allowEdit = ((string) $this->element['edit'] == 'true'); $allowClear = ((string) $this->element['clear'] != 'false'); $allowSelect = ((string) $this->element['select'] != 'false'); // Load language Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR); // The active weblink id field. $value = (int) $this->value > 0 ? (int) $this->value : ''; // Create the modal id. $modalId = 'Weblink_' . $this->id; /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); // Add the modal field script to the document head. $wa->useScript('field.modal-fields'); // Script to proxy the select modal function to the modal-fields.js file. if ($allowSelect) { static $scriptSelect = null; if (is_null($scriptSelect)) { $scriptSelect = []; } if (!isset($scriptSelect[$this->id])) { $wa->addInlineScript( " window.jSelectWeblink_" . $this->id . " = function (id, title, catid, object, url, language) { window.processModalSelect('Article', '" . $this->id . "', id, title, catid, object, url, language); }", [], ['type' => 'module'] ); Text::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); $scriptSelect[$this->id] = true; } } // Setup variables for display. $linkWeblinks = 'index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&' . Session::getFormToken() . '=1'; $linkWeblink = 'index.php?option=com_weblinks&view=weblink&layout=modal&tmpl=component&' . Session::getFormToken() . '=1'; $modalTitle = Text::_('COM_WEBLINKS_CHANGE_WEBLINK'); if (isset($this->element['language'])) { $linkWeblinks .= '&forcedLanguage=' . $this->element['language']; $linkWeblink .= '&forcedLanguage=' . $this->element['language']; $modalTitle .= ' — ' . $this->element['label']; } $urlSelect = $linkWeblinks . '&function=jSelectWeblink_' . $this->id; $urlEdit = $linkWeblink . '&task=weblink.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \''; $urlNew = $linkWeblink . '&task=weblink.add'; if ($value) { $db = Factory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('title')) ->from($db->quoteName('#__weblinks')) ->where($db->quoteName('id') . ' = :id') ->bind(':id', $value, ParameterType::INTEGER); $db->setQuery($query); try { $title = $db->loadResult(); } catch (\RuntimeException $e) { Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); } } $title = empty($title) ? Text::_('COM_WEBLINKS_SELECT_A_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); // The current weblink display field. $html = ''; if ($allowSelect || $allowNew || $allowEdit || $allowClear) { $html .= ''; } $html .= ''; // Select weblink button if ($allowSelect) { $html .= '' . ' ' . Text::_('JSELECT') . ''; } // New weblink button if ($allowNew) { $html .= '' . ' ' . Text::_('JACTION_CREATE') . ''; } // Edit weblink button if ($allowEdit) { $html .= '' . ' ' . Text::_('JACTION_EDIT') . ''; } // Clear weblink button if ($allowClear) { $html .= '' . ' ' . Text::_('JCLEAR') . ''; } if ($allowSelect || $allowNew || $allowEdit || $allowClear) { $html .= ''; } // Select weblink modal if ($allowSelect) { $html .= HTMLHelper::_('bootstrap.renderModal', 'ModalSelect' . $modalId, [ 'title' => $modalTitle, 'url' => $urlSelect, 'height' => '400px', 'width' => '800px', 'bodyHeight' => 70, 'modalWidth' => 80, 'footer' => '', ]); } $closeButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'cancel', 'weblink-form'); return false;"; $saveButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'save', 'weblink-form'); return false;"; $applyButtonClick = "window.processModalEdit(this, '$this->id', 'add', 'weblink', 'apply', 'weblink-form'); return false;"; // New weblink modal if ($allowNew) { $html .= HTMLHelper::_('bootstrap.renderModal', 'ModalNew' . $modalId, [ 'title' => Text::_('COM_WEBLINKS_NEW_WEBLINK'), 'backdrop' => 'static', 'keyboard' => false, 'closeButton' => false, 'url' => $urlNew, 'height' => '400px', 'width' => '800px', 'bodyHeight' => '70', 'modalWidth' => '80', 'footer' => '' . '' . '', ]); } // Edit weblink modal if ($allowEdit) { $html .= HTMLHelper::_('bootstrap.renderModal', 'ModalEdit' . $modalId, [ 'title' => Text::_('COM_WEBLINKS_EDIT_WEBLINK'), 'backdrop' => 'static', 'keyboard' => false, 'closeButton' => false, 'url' => $urlEdit, 'height' => '400px', 'width' => '800px', 'bodyHeight' => '70', 'modalWidth' => '80', 'footer' => '' . '' . '', ]); } // Note: class='required' for client side validation. $class = $this->required ? ' class="required modal-value"' : ''; $html .= ''; return $html; } /** * Method to get the field label markup. * * @return string The field label markup. * * @since __DEPLOY_VERSION__ */ protected function getLabel() { return str_replace($this->id, $this->id . '_name', parent::getLabel()); } }