"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php" (26 Nov 2020, 2171 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "UserUpdate7002.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\user\Plugin\migrate\process\d6;
    4 
    5 use Drupal\migrate\MigrateExecutableInterface;
    6 use Drupal\migrate\ProcessPluginBase;
    7 use Drupal\migrate\Row;
    8 use Drupal\Core\Config\Config;
    9 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
   10 use Symfony\Component\DependencyInjection\ContainerInterface;
   11 
   12 /**
   13  * Converts user time zones from time zone offsets to time zone names.
   14  *
   15  * @MigrateProcessPlugin(
   16  *   id = "user_update_7002"
   17  * )
   18  */
   19 class UserUpdate7002 extends ProcessPluginBase implements ContainerFactoryPluginInterface {
   20 
   21   /**
   22    * System timezones.
   23    *
   24    * @var array
   25    */
   26   protected static $timezones;
   27 
   28   /**
   29    * Contains the system.theme configuration object.
   30    *
   31    * @var \Drupal\Core\Config\Config
   32    */
   33   protected $dateConfig;
   34 
   35   /**
   36    * {@inheritdoc}
   37    */
   38   public function __construct(array $configuration, $plugin_id, array $plugin_definition, Config $date_config) {
   39     parent::__construct($configuration, $plugin_id, $plugin_definition);
   40     $this->dateConfig = $date_config;
   41     if (!isset(static::$timezones)) {
   42       static::$timezones = system_time_zones();
   43     }
   44   }
   45 
   46   /**
   47    * {@inheritdoc}
   48    */
   49   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
   50     return new static(
   51       $configuration,
   52       $plugin_id,
   53       $plugin_definition,
   54       $container->get('config.factory')->get('system.date')
   55     );
   56   }
   57 
   58   /**
   59    * {@inheritdoc}
   60    */
   61   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
   62     $timezone = NULL;
   63 
   64     if ($row->hasSourceProperty('timezone_name')) {
   65       if (isset(static::$timezones[$row->getSourceProperty('timezone_name')])) {
   66         $timezone = $row->getSourceProperty('timezone_name');
   67       }
   68     }
   69     if (!$timezone && $row->hasSourceProperty('event_timezone')) {
   70       if (isset(static::$timezones[$row->getSourceProperty('event_timezone')])) {
   71         $timezone = $row->getSourceProperty('event_timezone');
   72       }
   73     }
   74 
   75     if ($timezone === NULL) {
   76       $timezone = $this->dateConfig->get('timezone.default');
   77     }
   78     return $timezone;
   79   }
   80 
   81 }