[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/system/privacyconsent/src/Field/ -> PrivacyField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  System.privacyconsent
   6   *
   7   * @copyright   (C) 2018 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\System\PrivacyConsent\Field;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Field\RadioField;
  15  use Joomla\CMS\Language\Multilanguage;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\Component\Content\Site\Helper\RouteHelper;
  18  use Joomla\Database\ParameterType;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('JPATH_PLATFORM') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Provides input for privacy
  26   *
  27   * @since  3.9.0
  28   */
  29  class PrivacyField extends RadioField
  30  {
  31      /**
  32       * The form field type.
  33       *
  34       * @var    string
  35       * @since  3.9.0
  36       */
  37      protected $type = 'privacy';
  38  
  39      /**
  40       * Method to get the field input markup.
  41       *
  42       * @return  string   The field input markup.
  43       *
  44       * @since   3.9.0
  45       */
  46      protected function getInput()
  47      {
  48          // Display the message before the field
  49          echo $this->getRenderer('plugins.system.privacyconsent.message')->render($this->getLayoutData());
  50  
  51          return parent::getInput();
  52      }
  53  
  54      /**
  55       * Method to get the field label markup.
  56       *
  57       * @return  string  The field label markup.
  58       *
  59       * @since   3.9.0
  60       */
  61      protected function getLabel()
  62      {
  63          if ($this->hidden) {
  64              return '';
  65          }
  66  
  67          return $this->getRenderer('plugins.system.privacyconsent.label')->render($this->getLayoutData());
  68      }
  69  
  70      /**
  71       * Method to get the data to be passed to the layout for rendering.
  72       *
  73       * @return  array
  74       *
  75       * @since   3.9.4
  76       */
  77      protected function getLayoutData()
  78      {
  79          $data = parent::getLayoutData();
  80  
  81          $article = false;
  82          $link = false;
  83          $privacyArticle = $this->element['article'] > 0 ? (int) $this->element['article'] : 0;
  84  
  85          if ($privacyArticle && Factory::getApplication()->isClient('site')) {
  86              $db    = $this->getDatabase();
  87              $query = $db->getQuery(true)
  88                  ->select($db->quoteName(['id', 'alias', 'catid', 'language']))
  89                  ->from($db->quoteName('#__content'))
  90                  ->where($db->quoteName('id') . ' = :id')
  91                  ->bind(':id', $privacyArticle, ParameterType::INTEGER);
  92              $db->setQuery($query);
  93              $article = $db->loadObject();
  94  
  95              $slug = $article->alias ? ($article->id . ':' . $article->alias) : $article->id;
  96              $article->link  = RouteHelper::getArticleRoute($slug, $article->catid, $article->language);
  97              $link = $article->link;
  98          }
  99  
 100          $privacyMenuItem = $this->element['menu_item'] > 0 ? (int) $this->element['menu_item'] : 0;
 101  
 102          if ($privacyMenuItem && Factory::getApplication()->isClient('site')) {
 103              $link = 'index.php?Itemid=' . $privacyMenuItem;
 104  
 105              if (Multilanguage::isEnabled()) {
 106                  $db    = $this->getDatabase();
 107                  $query = $db->getQuery(true)
 108                      ->select($db->quoteName(['id', 'language']))
 109                      ->from($db->quoteName('#__menu'))
 110                      ->where($db->quoteName('id') . ' = :id')
 111                      ->bind(':id', $privacyMenuItem, ParameterType::INTEGER);
 112                  $db->setQuery($query);
 113                  $menuItem = $db->loadObject();
 114  
 115                  $link .= '&lang=' . $menuItem->language;
 116              }
 117          }
 118  
 119          $extraData = [
 120              'privacynote' => !empty($this->element['note']) ? $this->element['note'] : Text::_('PLG_SYSTEM_PRIVACYCONSENT_NOTE_FIELD_DEFAULT'),
 121              'options' => $this->getOptions(),
 122              'value'   => (string) $this->value,
 123              'translateLabel' => $this->translateLabel,
 124              'translateDescription' => $this->translateDescription,
 125              'translateHint' => $this->translateHint,
 126              'privacyArticle' => $privacyArticle,
 127              'article' => $article,
 128              'privacyLink' => $link,
 129          ];
 130  
 131          return array_merge($data, $extraData);
 132      }
 133  }


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