element['new'] == 'true'); $allowEdit = ((string) $this->element['edit'] == 'true'); $allowClear = ((string) $this->element['clear'] != 'false'); $allowSelect = ((string) $this->element['select'] != 'false'); // Load language JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); // The active article id field. $value = (int) $this->value > 0 ? (int) $this->value : ''; // Create the modal id. $modalId = 'Article_' . $this->id; // Add the modal field script to the document head. JHtml::_('jquery.framework'); JHtml::_('script', 'system/modal-fields.js', array('version' => 'auto', 'relative' => true)); // Script to proxy the select modal function to the modal-fields.js file. if ($allowSelect) { static $scriptSelect = null; if (is_null($scriptSelect)) { $scriptSelect = array(); } if (!isset($scriptSelect[$this->id])) { JFactory::getDocument()->addScriptDeclaration(" function jSelectArticle_" . $this->id . "(id, title, catid, object, url, language) { window.processModalSelect('Article', '" . $this->id . "', id, title, catid, object, url, language); } "); $scriptSelect[$this->id] = true; } } // Setup variables for display. $linkArticles = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1'; $linkArticle = 'index.php?option=com_content&view=article&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1'; if (isset($this->element['language'])) { $linkArticles .= '&forcedLanguage=' . $this->element['language']; $linkArticle .= '&forcedLanguage=' . $this->element['language']; $modalTitle = JText::_('COM_CONTENT_CHANGE_ARTICLE') . ' — ' . $this->element['label']; } else { $modalTitle = JText::_('COM_CONTENT_CHANGE_ARTICLE'); } $urlSelect = $linkArticles . '&function=jSelectArticle_' . $this->id; $urlEdit = $linkArticle . '&task=article.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \''; $urlNew = $linkArticle . '&task=article.add'; if ($value) { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('title')) ->from($db->quoteName('#__content')) ->where($db->quoteName('id') . ' = ' . (int) $value); $db->setQuery($query); try { $title = $db->loadResult(); } catch (RuntimeException $e) { JError::raiseWarning(500, $e->getMessage()); } } $title = empty($title) ? JText::_('COM_CONTENT_SELECT_AN_ARTICLE') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); // The current article display field. $html = ''; $html .= ''; // Select article button if ($allowSelect) { $html .= '' . ' ' . JText::_('JSELECT') . ''; } // New article button if ($allowNew) { $html .= '' . ' ' . JText::_('JACTION_CREATE') . ''; } // Edit article button if ($allowEdit) { $html .= '' . ' ' . JText::_('JACTION_EDIT') . ''; } // Clear article button if ($allowClear) { $html .= '' . '' . JText::_('JCLEAR') . ''; } $html .= ''; // Select article modal if ($allowSelect) { $html .= JHtml::_( 'bootstrap.renderModal', 'ModalSelect' . $modalId, array( 'title' => $modalTitle, 'url' => $urlSelect, 'height' => '400px', 'width' => '800px', 'bodyHeight' => '70', 'modalWidth' => '80', 'footer' => '', ) ); } // New article modal if ($allowNew) { $html .= JHtml::_( 'bootstrap.renderModal', 'ModalNew' . $modalId, array( 'title' => JText::_('COM_CONTENT_NEW_ARTICLE'), 'backdrop' => 'static', 'keyboard' => false, 'closeButton' => false, 'url' => $urlNew, 'height' => '400px', 'width' => '800px', 'bodyHeight' => '70', 'modalWidth' => '80', 'footer' => '' . '' . '', ) ); } // Edit article modal if ($allowEdit) { $html .= JHtml::_( 'bootstrap.renderModal', 'ModalEdit' . $modalId, array( 'title' => JText::_('COM_CONTENT_EDIT_ARTICLE'), '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 3.4 */ protected function getLabel() { return str_replace($this->id, $this->id . '_id', parent::getLabel()); } }