[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/user/profile/src/Field/ -> TosField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  User.profile
   6   *
   7   * @copyright   (C) 2012 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\Plugin\User\Profile\Field;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Field\RadioField;
  15  use Joomla\CMS\HTML\HTMLHelper;
  16  use Joomla\CMS\Language\Associations;
  17  use Joomla\CMS\Language\Text;
  18  use Joomla\CMS\Router\Route;
  19  use Joomla\Component\Content\Site\Helper\RouteHelper;
  20  use Joomla\Database\ParameterType;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('JPATH_PLATFORM') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Provides input for TOS
  28   *
  29   * @since  2.5.5
  30   */
  31  class TosField extends RadioField
  32  {
  33      /**
  34       * The form field type.
  35       *
  36       * @var    string
  37       * @since  2.5.5
  38       */
  39      protected $type = 'Tos';
  40  
  41      /**
  42       * Method to get the field label markup.
  43       *
  44       * @return  string  The field label markup.
  45       *
  46       * @since   2.5.5
  47       */
  48      protected function getLabel()
  49      {
  50          $label = '';
  51  
  52          if ($this->hidden) {
  53              return $label;
  54          }
  55  
  56          // Get the label text from the XML element, defaulting to the element name.
  57          $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
  58          $text = $this->translateLabel ? Text::_($text) : $text;
  59  
  60          // Set required to true as this field is not displayed at all if not required.
  61          $this->required = true;
  62  
  63          // Build the class for the label.
  64          $class = !empty($this->description) ? 'hasPopover' : '';
  65          $class = $class . ' required';
  66          $class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class;
  67  
  68          // Add the opening label tag and main attributes attributes.
  69          $label .= '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '"';
  70  
  71          // If a description is specified, use it to build a tooltip.
  72          if (!empty($this->description)) {
  73              HTMLHelper::_('bootstrap.popover', '.hasPopover');
  74              $label .= ' data-bs-content="' . htmlspecialchars(
  75                  $this->translateDescription ? Text::_($this->description) : $this->description,
  76                  ENT_COMPAT,
  77                  'UTF-8'
  78              ) . '"';
  79  
  80              if (Factory::getLanguage()->isRtl()) {
  81                  $label .= ' data-bs-placement="left"';
  82              }
  83          }
  84  
  85          $tosArticle = $this->element['article'] > 0 ? (int) $this->element['article'] : 0;
  86  
  87          if ($tosArticle) {
  88              $attribs                = [];
  89              $attribs['data-bs-toggle'] = 'modal';
  90              $attribs['data-bs-target'] = '#tosModal';
  91  
  92              $db    = $this->getDatabase();
  93              $query = $db->getQuery(true);
  94  
  95              $query->select($db->quoteName(['id', 'alias', 'catid', 'language']))
  96                  ->from($db->quoteName('#__content'))
  97                  ->where($db->quoteName('id') . ' = :id')
  98                  ->bind(':id', $tosArticle, ParameterType::INTEGER);
  99              $db->setQuery($query);
 100              $article = $db->loadObject();
 101  
 102              if (Associations::isEnabled()) {
 103                  $tosAssociated = Associations::getAssociations('com_content', '#__content', 'com_content.item', $tosArticle);
 104              }
 105  
 106              $currentLang = Factory::getLanguage()->getTag();
 107  
 108              if (isset($tosAssociated) && $currentLang !== $article->language && \array_key_exists($currentLang, $tosAssociated)) {
 109                  $url  = RouteHelper::getArticleRoute(
 110                      $tosAssociated[$currentLang]->id,
 111                      $tosAssociated[$currentLang]->catid,
 112                      $tosAssociated[$currentLang]->language
 113                  );
 114                  $link = HTMLHelper::_('link', Route::_($url . '&tmpl=component'), $text, $attribs);
 115              } else {
 116                  $slug = $article->alias ? ($article->id . ':' . $article->alias) : $article->id;
 117                  $url  = RouteHelper::getArticleRoute($slug, $article->catid, $article->language);
 118                  $link = HTMLHelper::_('link', Route::_($url . '&tmpl=component'), $text, $attribs);
 119              }
 120  
 121              echo HTMLHelper::_(
 122                  'bootstrap.renderModal',
 123                  'tosModal',
 124                  [
 125                      'url'    => Route::_($url . '&tmpl=component'),
 126                      'title'  => $text,
 127                      'height' => '100%',
 128                      'width'  => '100%',
 129                      'modalWidth'  => '800',
 130                      'bodyHeight'  => '500',
 131                      'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-hidden="true">'
 132                          . Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>',
 133                  ]
 134              );
 135          } else {
 136              $link = $text;
 137          }
 138  
 139          // Add the label text and closing tag.
 140          $label .= '>' . $link . '<span class="star" aria-hidden="true">&#160;*</span></label>';
 141  
 142          return $label;
 143      }
 144  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer