[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_contact/src/Extension/ -> ContactComponent.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_contact
   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\Component\Contact\Administrator\Extension;
  12  
  13  use Joomla\CMS\Association\AssociationServiceInterface;
  14  use Joomla\CMS\Association\AssociationServiceTrait;
  15  use Joomla\CMS\Categories\CategoryServiceInterface;
  16  use Joomla\CMS\Categories\CategoryServiceTrait;
  17  use Joomla\CMS\Component\Router\RouterServiceInterface;
  18  use Joomla\CMS\Component\Router\RouterServiceTrait;
  19  use Joomla\CMS\Extension\BootableExtensionInterface;
  20  use Joomla\CMS\Extension\MVCComponent;
  21  use Joomla\CMS\Factory;
  22  use Joomla\CMS\Fields\FieldsServiceInterface;
  23  use Joomla\CMS\Form\Form;
  24  use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
  25  use Joomla\CMS\Language\Text;
  26  use Joomla\CMS\Tag\TagServiceInterface;
  27  use Joomla\CMS\Tag\TagServiceTrait;
  28  use Joomla\CMS\User\UserFactoryInterface;
  29  use Joomla\Component\Contact\Administrator\Service\HTML\AdministratorService;
  30  use Joomla\Component\Contact\Administrator\Service\HTML\Icon;
  31  use Psr\Container\ContainerInterface;
  32  
  33  // phpcs:disable PSR1.Files.SideEffects
  34  \defined('JPATH_PLATFORM') or die;
  35  // phpcs:enable PSR1.Files.SideEffects
  36  
  37  /**
  38   * Component class for com_contact
  39   *
  40   * @since  4.0.0
  41   */
  42  class ContactComponent extends MVCComponent implements
  43      BootableExtensionInterface,
  44      CategoryServiceInterface,
  45      FieldsServiceInterface,
  46      AssociationServiceInterface,
  47      RouterServiceInterface,
  48      TagServiceInterface
  49  {
  50      use AssociationServiceTrait;
  51      use HTMLRegistryAwareTrait;
  52      use RouterServiceTrait;
  53      use CategoryServiceTrait, TagServiceTrait {
  54          CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait;
  55          CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
  56      }
  57  
  58      /**
  59       * Booting the extension. This is the function to set up the environment of the extension like
  60       * registering new class loaders, etc.
  61       *
  62       * If required, some initial set up can be done from services of the container, eg.
  63       * registering HTML services.
  64       *
  65       * @param   ContainerInterface  $container  The container
  66       *
  67       * @return  void
  68       *
  69       * @since   4.0.0
  70       */
  71      public function boot(ContainerInterface $container)
  72      {
  73          $this->getRegistry()->register('contactadministrator', new AdministratorService());
  74          $this->getRegistry()->register('contacticon', new Icon($container->get(UserFactoryInterface::class)));
  75      }
  76  
  77      /**
  78       * Returns a valid section for the given section. If it is not valid then null
  79       * is returned.
  80       *
  81       * @param   string  $section  The section to get the mapping for
  82       * @param   object  $item     The item
  83       *
  84       * @return  string|null  The new section
  85       *
  86       * @since   4.0.0
  87       */
  88      public function validateSection($section, $item = null)
  89      {
  90          if (Factory::getApplication()->isClient('site') && $section == 'contact' && $item instanceof Form) {
  91              // The contact form needs to be the mail section
  92              $section = 'mail';
  93          }
  94  
  95          if (Factory::getApplication()->isClient('site') && ($section === 'category' || $section === 'form')) {
  96              // The contact form needs to be the mail section
  97              $section = 'contact';
  98          }
  99  
 100          if ($section !== 'mail' && $section !== 'contact') {
 101              // We don't know other sections
 102              return null;
 103          }
 104  
 105          return $section;
 106      }
 107  
 108      /**
 109       * Returns valid contexts
 110       *
 111       * @return  array
 112       *
 113       * @since   4.0.0
 114       */
 115      public function getContexts(): array
 116      {
 117          Factory::getLanguage()->load('com_contact', JPATH_ADMINISTRATOR);
 118  
 119          $contexts = array(
 120              'com_contact.contact'    => Text::_('COM_CONTACT_FIELDS_CONTEXT_CONTACT'),
 121              'com_contact.mail'       => Text::_('COM_CONTACT_FIELDS_CONTEXT_MAIL'),
 122              'com_contact.categories' => Text::_('JCATEGORY')
 123          );
 124  
 125          return $contexts;
 126      }
 127  
 128      /**
 129       * Returns the table for the count items functions for the given section.
 130       *
 131       * @param   string  $section  The section
 132       *
 133       * @return  string|null
 134       *
 135       * @since   4.0.0
 136       */
 137      protected function getTableNameForSection(string $section = null)
 138      {
 139          return ($section === 'category' ? 'categories' : 'contact_details');
 140      }
 141  
 142      /**
 143       * Returns the state column for the count items functions for the given section.
 144       *
 145       * @param   string  $section  The section
 146       *
 147       * @return  string|null
 148       *
 149       * @since   4.0.0
 150       */
 151      protected function getStateColumnForSection(string $section = null)
 152      {
 153          return 'published';
 154      }
 155  }


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