From 6e762ed5df4c0a05a304c6c081796f3b2c180f8d Mon Sep 17 00:00:00 2001 From: owenbush <ojb@ukhhf.co.uk> Date: Mon, 30 Mar 2020 13:23:00 -0600 Subject: [PATCH] Update coding standards in recurring_events core module --- ...urring_events.eventseries_type.default.yml | 2 +- recurring_events.api.php | 4 +- recurring_events.info.yml | 2 +- recurring_events.install | 1 - recurring_events.libraries.yml | 2 +- recurring_events.module | 8 +-- recurring_events.permissions.yml | 2 +- recurring_events.routing.yml | 2 +- recurring_events.services.yml | 2 +- src/Entity/EventInstance.php | 15 ---- src/Entity/EventSeries.php | 15 ---- src/EventCreationService.php | 69 ++++++++++++------- src/EventInstanceTypeHtmlRouteProvider.php | 3 - src/EventInterface.php | 25 ------- src/EventSeriesTypeHtmlRouteProvider.php | 4 -- src/ExcludedDatesHtmlRouteProvider.php | 4 -- src/Form/EventInstanceForm.php | 36 ++++++++-- src/Form/EventInstanceRevisionDeleteForm.php | 7 +- src/Form/EventInstanceRevisionRevertForm.php | 9 ++- ...tInstanceRevisionRevertTranslationForm.php | 5 +- src/Form/EventInstanceTypeForm.php | 32 ++++++++- src/Form/EventSeriesForm.php | 69 +++++++++++++++---- src/Form/EventSeriesRevisionDeleteForm.php | 7 +- src/Form/EventSeriesRevisionRevertForm.php | 9 ++- ...entSeriesRevisionRevertTranslationForm.php | 20 ++++-- src/Form/EventSeriesSettingsForm.php | 44 +++++++++--- src/Form/EventSeriesTypeForm.php | 32 ++++++++- src/IncludedDatesHtmlRouteProvider.php | 4 -- .../EventInstanceDateFormatter.php | 17 +++-- .../FieldType/ConsecutiveRecurringDate.php | 3 +- .../Field/FieldType/DailyRecurringDate.php | 3 +- .../Field/FieldType/MonthlyRecurringDate.php | 1 - .../Field/FieldType/WeeklyRecurringDate.php | 1 - 33 files changed, 294 insertions(+), 165 deletions(-) diff --git a/config/install/recurring_events.eventseries_type.default.yml b/config/install/recurring_events.eventseries_type.default.yml index e1b9ee50..f3865a6e 100644 --- a/config/install/recurring_events.eventseries_type.default.yml +++ b/config/install/recurring_events.eventseries_type.default.yml @@ -3,4 +3,4 @@ status: true dependencies: { } label: Default id: default -description: 'A default event series type.' \ No newline at end of file +description: 'A default event series type.' diff --git a/recurring_events.api.php b/recurring_events.api.php index ade58157..fdfadb85 100644 --- a/recurring_events.api.php +++ b/recurring_events.api.php @@ -90,7 +90,7 @@ function hook_recurring_events_form_config_array_alter(array &$form_config = []) */ function hook_recurring_events_entity_config_array_alter(array &$entity_config = []) { // Remove the first custom date. - unset($form_config['custom_dates'][0]); + unset($entity_config['custom_dates'][0]); } /** @@ -101,7 +101,7 @@ function hook_recurring_events_entity_config_array_alter(array &$entity_config = */ function hook_recurring_events_diff_array_alter(array &$diff = []) { // Do not show differences in custom dates. - unset($form_config['custom_dates']); + unset($diff['custom_dates']); } /** diff --git a/recurring_events.info.yml b/recurring_events.info.yml index ff596636..9b534c83 100644 --- a/recurring_events.info.yml +++ b/recurring_events.info.yml @@ -7,4 +7,4 @@ package: 'Recurring Events' dependencies: - drupal:datetime_range - drupal:options - - field_inheritance:field_inheritance \ No newline at end of file + - field_inheritance:field_inheritance diff --git a/recurring_events.install b/recurring_events.install index 1f4c1a06..b4dfdf04 100644 --- a/recurring_events.install +++ b/recurring_events.install @@ -291,7 +291,6 @@ function recurring_events_update_8007() { if (!empty($inherited_fields)) { foreach ($inherited_fields as $inherited_field) { $field = \Drupal::configFactory()->getEditable($inherited_field); - $original_id = $field->getName(); foreach ($bundles as $bundle_key => $bundle) { $data = $field->getRawData(); $id_parts = [ diff --git a/recurring_events.libraries.yml b/recurring_events.libraries.yml index 79e065df..6950c953 100644 --- a/recurring_events.libraries.yml +++ b/recurring_events.libraries.yml @@ -12,4 +12,4 @@ recurring_events.date_form: js/recurring_events_date_form.js: {} dependencies: - core/drupal - - core/jquery \ No newline at end of file + - core/jquery diff --git a/recurring_events.module b/recurring_events.module index 6b2b43ba..b305b87f 100644 --- a/recurring_events.module +++ b/recurring_events.module @@ -592,12 +592,12 @@ function recurring_events_recurring_events_event_instances_pre_create_alter(arra $end = $dates['end_date']->getTimestamp(); for ($x = 0; $x < (count($include) - 1); $x++) { - $include_start = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $include[$x]['value'] . 'T00:00:00'); - $include_start = $include_start->getTimestamp(); + $included_start = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $include[$x]['value'] . 'T00:00:00'); + $included_start = $included_start->getTimestamp(); $included_end = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $include[$x]['end_value'] . 'T23:59:59'); $included_end = $included_end->getTimestamp(); - if ($start >= $include_start && $start <= $included_end && $end >= $included_start && $end <= $included_end) { + if ($start >= $included_start && $start <= $included_end && $end >= $included_start && $end <= $included_end) { // This event is in the inclusion range, so move on to the next one. break; } @@ -620,7 +620,7 @@ function recurring_events_recurring_events_event_instances_pre_create_alter(arra function recurring_events_allowed_values_function(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL) { $values = ['custom' => t('Custom Event')]; $fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('eventseries'); - foreach ($fields as $field_name => $field) { + foreach ($fields as $field) { $field_definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType()); $class = new \ReflectionClass($field_definition['class']); if ($class->implementsInterface('\Drupal\recurring_events\RecurringEventsFieldTypeInterface')) { diff --git a/recurring_events.permissions.yml b/recurring_events.permissions.yml index 43ce6ea4..76e21274 100644 --- a/recurring_events.permissions.yml +++ b/recurring_events.permissions.yml @@ -89,4 +89,4 @@ administer eventseries types: administer eventinstance types: title: 'Administer eventinstance types' description: 'Manage types of eventinstance.' - restrict access: true \ No newline at end of file + restrict access: true diff --git a/recurring_events.routing.yml b/recurring_events.routing.yml index b603337a..e23c6d1f 100644 --- a/recurring_events.routing.yml +++ b/recurring_events.routing.yml @@ -235,4 +235,4 @@ entity.eventinstance_type.collection: requirements: _permission: 'administer eventinstance types' options: - _admin_route: TRUE \ No newline at end of file + _admin_route: TRUE diff --git a/recurring_events.services.yml b/recurring_events.services.yml index 4e599cb4..41b953f2 100644 --- a/recurring_events.services.yml +++ b/recurring_events.services.yml @@ -1,4 +1,4 @@ services: recurring_events.event_creation_service: class: Drupal\recurring_events\EventCreationService - arguments: ['@string_translation', '@database', '@logger.factory', '@messenger', '@plugin.manager.field.field_type', '@entity_field.manager'] + arguments: ['@string_translation', '@database', '@logger.factory', '@messenger', '@plugin.manager.field.field_type', '@entity_field.manager', '@module_handler', '@entity_type.manager'] diff --git a/src/Entity/EventInstance.php b/src/Entity/EventInstance.php index 14c5af95..54c153a8 100644 --- a/src/Entity/EventInstance.php +++ b/src/Entity/EventInstance.php @@ -279,21 +279,6 @@ class EventInstance extends EditorialContentEntityBase implements EventInterface return $this; } - /** - * {@inheritdoc} - */ - public function getRevisionAuthor() { - return $this->getRevisionUser(); - } - - /** - * {@inheritdoc} - */ - public function setRevisionAuthorId($uid) { - $this->setRevisionUserId($uid); - return $this; - } - /** * {@inheritdoc} * diff --git a/src/Entity/EventSeries.php b/src/Entity/EventSeries.php index 572f3efc..729d3da7 100644 --- a/src/Entity/EventSeries.php +++ b/src/Entity/EventSeries.php @@ -280,21 +280,6 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface { return $this; } - /** - * {@inheritdoc} - */ - public function getRevisionAuthor() { - return $this->getRevisionUser(); - } - - /** - * {@inheritdoc} - */ - public function setRevisionAuthorId($uid) { - $this->setRevisionUserId($uid); - return $this; - } - /** * {@inheritdoc} * diff --git a/src/EventCreationService.php b/src/EventCreationService.php index 992583d8..66d9b258 100644 --- a/src/EventCreationService.php +++ b/src/EventCreationService.php @@ -12,12 +12,17 @@ use Drupal\Core\Messenger\Messenger; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\Core\Entity\EntityFieldManager; use Drupal\Core\Field\FieldTypePluginManager; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Extension\ModuleHandler; +use Drupal\Core\Entity\EntityTypeManagerInterface; /** * EventCreationService class. */ class EventCreationService { + use StringTranslationTrait; + /** * The translation interface. * @@ -60,6 +65,20 @@ class EventCreationService { */ protected $entityFieldManager; + /** + * The module handler service. + * + * @var \Drupal\Core\Extension\ModuleHandler + */ + protected $moduleHandler; + + /** + * The entity type manager service. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + /** * Class constructor. * @@ -75,14 +94,20 @@ class EventCreationService { * The field type plugin manager. * @param \Drupal\Core\Entity\EntityFieldManager $entity_field_manager * The entity field manager. + * @param \Drupal\Core\Extension\ModuleHandler $module_handler + * The module handler service. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager service. */ - public function __construct(TranslationInterface $translation, Connection $database, LoggerChannelFactoryInterface $logger, Messenger $messenger, FieldTypePluginManager $field_type_plugin_manager, EntityFieldManager $entity_field_manager) { + public function __construct(TranslationInterface $translation, Connection $database, LoggerChannelFactoryInterface $logger, Messenger $messenger, FieldTypePluginManager $field_type_plugin_manager, EntityFieldManager $entity_field_manager, ModuleHandler $module_handler, EntityTypeManagerInterface $entity_type_manager) { $this->translation = $translation; $this->database = $database; $this->loggerFactory = $logger->get('recurring_events'); $this->messenger = $messenger; $this->fieldTypePluginManager = $field_type_plugin_manager; $this->entityFieldManager = $entity_field_manager; + $this->moduleHandler = $module_handler; + $this->entityTypeManager = $entity_type_manager; } /** @@ -95,7 +120,9 @@ class EventCreationService { $container->get('logger.factory'), $container->get('messenger'), $container->get('plugin.manager.field.field_type'), - $container->get('entity_field.manager') + $container->get('entity_field.manager'), + $container->get('module_handler'), + $container->get('entity_type.manager') ); } @@ -157,7 +184,7 @@ class EventCreationService { $config += $field_class::convertEntityConfigToArray($event); } - \Drupal::moduleHandler()->alter('recurring_events_entity_config_array', $config); + $this->moduleHandler->alter('recurring_events_entity_config_array', $config); return $config; } @@ -224,7 +251,7 @@ class EventCreationService { $config += $field_class::convertFormConfigToArray($form_state); } - \Drupal::moduleHandler()->alter('recurring_events_form_config_array', $config); + $this->moduleHandler->alter('recurring_events_form_config_array', $config); return $config; } @@ -296,7 +323,7 @@ class EventCreationService { } } - foreach ($form_config['custom_dates'] as $dates) { + foreach ($form_config['custom_dates'] as $date) { if (!empty($date['start_date']) && !empty($date['end_date'])) { $overridden_start_ends[] = $date['start_date']->format('Y-m-d h:ia') . ' - ' . $date['end_date']->format('Y-m-d h:ia'); } @@ -316,7 +343,7 @@ class EventCreationService { } } - \Drupal::moduleHandler()->alter('recurring_events_diff_array', $diff); + $this->moduleHandler->alter('recurring_events_diff_array', $diff); return $diff; } @@ -339,21 +366,21 @@ class EventCreationService { $create_instances = $this->checkForOriginalRecurConfigChanges($event, $original); if ($create_instances) { // Allow other modules to react prior to the deletion of all instances. - \Drupal::moduleHandler()->invokeAll('recurring_events_save_pre_instances_deletion', [$event, $original]); + $this->moduleHandler->invokeAll('recurring_events_save_pre_instances_deletion', [$event, $original]); // Find all the instances and delete them. $instances = $event->event_instances->referencedEntities(); if (!empty($instances)) { - foreach ($instances as $index => $instance) { + foreach ($instances as $instance) { // Allow other modules to react prior to deleting a specific // instance after a date configuration change. - \Drupal::moduleHandler()->invokeAll('recurring_events_save_pre_instance_deletion', [$event, $instance]); + $this->moduleHandler->invokeAll('recurring_events_save_pre_instance_deletion', [$event, $instance]); $instance->delete(); // Allow other modules to react after deleting a specific instance // after a date configuration change. - \Drupal::moduleHandler()->invokeAll('recurring_events_save_post_instance_deletion', [$event, $instance]); + $this->moduleHandler->invokeAll('recurring_events_save_post_instance_deletion', [$event, $instance]); } $this->messenger->addStatus($this->translation->translate('A total of %count existing event instances were removed', [ '%count' => count($instances), @@ -361,7 +388,7 @@ class EventCreationService { } // Allow other modules to react after the deletion of all instances. - \Drupal::moduleHandler()->invokeAll('recurring_events_save_post_instances_deletion', [$event, $original]); + $this->moduleHandler->invokeAll('recurring_events_save_post_instances_deletion', [$event, $original]); } } @@ -381,9 +408,6 @@ class EventCreationService { $form_data = $this->convertEntityConfigToArray($event); $event_instances = []; - $timezone = new \DateTimeZone(date_default_timezone_get()); - $utc_timezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE); - if (!empty($form_data['type'])) { if ($form_data['type'] === 'custom') { if (!empty($form_data['custom_dates'])) { @@ -398,7 +422,7 @@ class EventCreationService { // Allow modules to alter the array of event instances before they // get created. - \Drupal::moduleHandler()->alter('recurring_events_event_instances_pre_create', $events_to_create, $event); + $this->moduleHandler->alter('recurring_events_event_instances_pre_create', $events_to_create, $event); if (!empty($events_to_create)) { foreach ($events_to_create as $custom_event) { @@ -414,7 +438,7 @@ class EventCreationService { // Allow modules to alter the array of event instances before they // get created. - \Drupal::moduleHandler()->alter('recurring_events_event_instances_pre_create', $events_to_create, $event); + $this->moduleHandler->alter('recurring_events_event_instances_pre_create', $events_to_create, $event); if (!empty($events_to_create)) { foreach ($events_to_create as $event_to_create) { @@ -454,12 +478,9 @@ class EventCreationService { 'type' => $event->getType(), ]; - \Drupal::moduleHandler()->alter('recurring_events_event_instance', $data); - - $entity = \Drupal::entityTypeManager() - ->getStorage('eventinstance') - ->create($data); + $this->moduleHandler->alter('recurring_events_event_instance', $data); + $entity = $this->entityTypeManager->getStorage('eventinstance')->create($data); $entity->save(); return $entity; @@ -533,7 +554,7 @@ class EventCreationService { // hook. $recur_fields = []; $fields = $this->entityFieldManager->getBaseFieldDefinitions('eventseries'); - foreach ($fields as $field_name => $field) { + foreach ($fields as $field) { $field_definition = $this->fieldTypePluginManager->getDefinition($field->getType()); $class = new \ReflectionClass($field_definition['class']); if ($class->implementsInterface('\Drupal\recurring_events\RecurringEventsFieldTypeInterface')) { @@ -541,9 +562,9 @@ class EventCreationService { } } - $recur_fields['custom'] = t('Custom Event'); + $recur_fields['custom'] = $this->t('Custom Event'); if ($allow_alter) { - \Drupal::moduleHandler()->alter('recurring_events_recur_field_types', $recur_fields); + $this->moduleHandler->alter('recurring_events_recur_field_types', $recur_fields); } return $recur_fields; } diff --git a/src/EventInstanceTypeHtmlRouteProvider.php b/src/EventInstanceTypeHtmlRouteProvider.php index 5cf22772..1d42c64e 100644 --- a/src/EventInstanceTypeHtmlRouteProvider.php +++ b/src/EventInstanceTypeHtmlRouteProvider.php @@ -18,9 +18,6 @@ class EventInstanceTypeHtmlRouteProvider extends AdminHtmlRouteProvider { */ public function getRoutes(EntityTypeInterface $entity_type) { $collection = parent::getRoutes($entity_type); - - // Provide your custom entity routes here. - return $collection; } diff --git a/src/EventInterface.php b/src/EventInterface.php index 6644e0c5..73df63b1 100644 --- a/src/EventInterface.php +++ b/src/EventInterface.php @@ -41,29 +41,4 @@ interface EventInterface extends ContentEntityInterface, EntityChangedInterface, */ public function setRevisionCreationTime($timestamp); - /** - * Gets the event revision author. - * - * @return \Drupal\user\UserInterface - * The user entity for the revision author. - * - * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use - * \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser() instead. - */ - public function getRevisionAuthor(); - - /** - * Sets the event revision author. - * - * @param int $uid - * The user ID of the revision author. - * - * @return \Drupal\recurring_events\EventInterface - * The called event entity. - * - * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use - * \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId() instead. - */ - public function setRevisionAuthorId($uid); - } diff --git a/src/EventSeriesTypeHtmlRouteProvider.php b/src/EventSeriesTypeHtmlRouteProvider.php index 8960f2c2..f2cf604d 100644 --- a/src/EventSeriesTypeHtmlRouteProvider.php +++ b/src/EventSeriesTypeHtmlRouteProvider.php @@ -4,7 +4,6 @@ namespace Drupal\recurring_events; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; -use Symfony\Component\Routing\Route; /** * Provides routes for Event series type entities. @@ -19,9 +18,6 @@ class EventSeriesTypeHtmlRouteProvider extends AdminHtmlRouteProvider { */ public function getRoutes(EntityTypeInterface $entity_type) { $collection = parent::getRoutes($entity_type); - - // Provide your custom entity routes here. - return $collection; } diff --git a/src/ExcludedDatesHtmlRouteProvider.php b/src/ExcludedDatesHtmlRouteProvider.php index edc38c0c..26996113 100644 --- a/src/ExcludedDatesHtmlRouteProvider.php +++ b/src/ExcludedDatesHtmlRouteProvider.php @@ -4,7 +4,6 @@ namespace Drupal\recurring_events; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; -use Symfony\Component\Routing\Route; /** * Provides routes for Excluded dates entities. @@ -19,9 +18,6 @@ class ExcludedDatesHtmlRouteProvider extends AdminHtmlRouteProvider { */ public function getRoutes(EntityTypeInterface $entity_type) { $collection = parent::getRoutes($entity_type); - - // Provide your custom entity routes here. - return $collection; } diff --git a/src/Form/EventInstanceForm.php b/src/Form/EventInstanceForm.php index ce3a1b77..97063871 100644 --- a/src/Form/EventInstanceForm.php +++ b/src/Form/EventInstanceForm.php @@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Messenger\Messenger; +use Drupal\Core\Session\AccountProxyInterface; +use Drupal\Component\Datetime\TimeInterface; /** * Form controller for the eventinstance entity edit forms. @@ -22,13 +24,29 @@ class EventInstanceForm extends ContentEntityForm { */ protected $messenger; + /** + * The current user. + * + * @var \Drupal\Core\Session\AccountProxyInterface + */ + protected $currentUser; + + /** + * The time service. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected $time; + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), - $container->get('messenger') + $container->get('messenger'), + $container->get('current_user'), + $container->get('datetime.time') ); } @@ -39,9 +57,15 @@ class EventInstanceForm extends ContentEntityForm { * The entity manager service. * @param \Drupal\Core\Messenger\Messenger $messenger * The messenger service. + * @param \Drupal\Core\Session\AccountProxyInterface $current_user + * The current user. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. */ - public function __construct(EntityManagerInterface $entity_manager, Messenger $messenger) { + public function __construct(EntityManagerInterface $entity_manager, Messenger $messenger, AccountProxyInterface $current_user, TimeInterface $time) { $this->messenger = $messenger; + $this->currentUser = $current_user; + $this->time = $time; parent::__construct($entity_manager); } @@ -96,8 +120,8 @@ class EventInstanceForm extends ContentEntityForm { $entity->setNewRevision(); // If a new revision is created, save the current user as revision author. - $entity->setRevisionCreationTime(\Drupal::time()->getRequestTime()); - $entity->setRevisionUserId(\Drupal::currentUser()->id()); + $entity->setRevisionCreationTime($this->time->getRequestTime()); + $entity->setRevisionUserId($this->currentUser->id()); } else { $entity->setNewRevision(FALSE); @@ -106,12 +130,12 @@ class EventInstanceForm extends ContentEntityForm { parent::save($form, $form_state); if ($entity->isDefaultTranslation()) { - $message = t('Event instance of %label has been saved.', [ + $message = $this->t('Event instance of %label has been saved.', [ '%label' => $entity->getEventSeries()->title->value, ]); } else { - $message = t('@language translation of the Event Instance %label has been saved.', [ + $message = $this->t('@language translation of the Event Instance %label has been saved.', [ '@language' => $entity->language()->getName(), '%label' => $entity->getUntranslated()->getEventSeries()->title->value, ]); diff --git a/src/Form/EventInstanceRevisionDeleteForm.php b/src/Form/EventInstanceRevisionDeleteForm.php index b67b92ad..fea21b46 100644 --- a/src/Form/EventInstanceRevisionDeleteForm.php +++ b/src/Form/EventInstanceRevisionDeleteForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Messenger\Messenger; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides a form for deleting a eventinstance revision. @@ -18,6 +19,8 @@ use Drupal\Core\Messenger\Messenger; */ class EventInstanceRevisionDeleteForm extends ConfirmFormBase { + use StringTranslationTrait; + /** * The eventinstance revision. * @@ -96,7 +99,7 @@ class EventInstanceRevisionDeleteForm extends ConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to delete the revision from %revision-date?', [ + return $this->t('Are you sure you want to delete the revision from %revision-date?', [ '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()), ]); } @@ -112,7 +115,7 @@ class EventInstanceRevisionDeleteForm extends ConfirmFormBase { * {@inheritdoc} */ public function getConfirmText() { - return t('Delete'); + return $this->t('Delete'); } /** diff --git a/src/Form/EventInstanceRevisionRevertForm.php b/src/Form/EventInstanceRevisionRevertForm.php index 87ee9b85..7eba0789 100644 --- a/src/Form/EventInstanceRevisionRevertForm.php +++ b/src/Form/EventInstanceRevisionRevertForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Url; use Drupal\recurring_events\EventInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Messenger\Messenger; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides a form for reverting an eventinstance revision. @@ -18,6 +19,8 @@ use Drupal\Core\Messenger\Messenger; */ class EventInstanceRevisionRevertForm extends ConfirmFormBase { + use StringTranslationTrait; + /** * The eventinstance revision. * @@ -84,7 +87,7 @@ class EventInstanceRevisionRevertForm extends ConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); + return $this->t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); } /** @@ -98,7 +101,7 @@ class EventInstanceRevisionRevertForm extends ConfirmFormBase { * {@inheritdoc} */ public function getConfirmText() { - return t('Revert'); + return $this->t('Revert'); } /** @@ -127,7 +130,7 @@ class EventInstanceRevisionRevertForm extends ConfirmFormBase { $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision = $this->prepareRevertedRevision($this->revision, $form_state); - $this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]); + $this->revision->revision_log = $this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]); $this->revision->save(); $this->logger('content')->notice('eventinstance: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); diff --git a/src/Form/EventInstanceRevisionRevertTranslationForm.php b/src/Form/EventInstanceRevisionRevertTranslationForm.php index c349d2c3..10f02f6e 100644 --- a/src/Form/EventInstanceRevisionRevertTranslationForm.php +++ b/src/Form/EventInstanceRevisionRevertTranslationForm.php @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\recurring_events\EventInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides form to revert an eventinstance revision for a single translation. @@ -16,6 +17,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class EventInstanceRevisionRevertTranslationForm extends EventInstanceRevisionRevertForm { + use StringTranslationTrait; + /** * The language to be reverted. * @@ -67,7 +70,7 @@ class EventInstanceRevisionRevertTranslationForm extends EventInstanceRevisionRe * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to revert @language translation to the revision from %revision-date?', ['@language' => $this->languageManager->getLanguageName($this->langcode), '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); + return $this->t('Are you sure you want to revert @language translation to the revision from %revision-date?', ['@language' => $this->languageManager->getLanguageName($this->langcode), '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); } /** diff --git a/src/Form/EventInstanceTypeForm.php b/src/Form/EventInstanceTypeForm.php index 32b513d8..0c9d369d 100644 --- a/src/Form/EventInstanceTypeForm.php +++ b/src/Form/EventInstanceTypeForm.php @@ -4,12 +4,40 @@ namespace Drupal\recurring_events\Form; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Messenger\Messenger; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Class EventInstanceTypeForm. */ class EventInstanceTypeForm extends EntityForm { + /** + * The messenger service. + * + * @var \Drupal\Core\Messenger\Messenger + */ + protected $messenger; + + /** + * Constructs a new EventSeriesTypeForm. + * + * @param \Drupal\Core\Messenger\Messenger $messenger + * The messenger service. + */ + public function __construct(Messenger $messenger) { + $this->messenger = $messenger; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('messenger') + ); + } + /** * {@inheritdoc} */ @@ -53,13 +81,13 @@ class EventInstanceTypeForm extends EntityForm { switch ($status) { case SAVED_NEW: - \Drupal::messenger()->addMessage($this->t('Created the %label event instance type.', [ + $this->messenger->addMessage($this->t('Created the %label event instance type.', [ '%label' => $eventinstance_type->label(), ])); break; default: - \Drupal::messenger()->addMessage($this->t('Saved the %label event instance type.', [ + $this->messenger->addMessage($this->t('Saved the %label event instance type.', [ '%label' => $eventinstance_type->label(), ])); } diff --git a/src/Form/EventSeriesForm.php b/src/Form/EventSeriesForm.php index cce0bd77..6e02c4c3 100644 --- a/src/Form/EventSeriesForm.php +++ b/src/Form/EventSeriesForm.php @@ -16,6 +16,9 @@ use Drupal\recurring_events\Plugin\Field\FieldWidget\ConsecutiveRecurringDateWid use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Component\Datetime\TimeInterface; +use Drupal\Core\Session\AccountProxyInterface; +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Extension\ModuleHandler; /** * Form controller for the eventseries entity create form. @@ -73,6 +76,34 @@ class EventSeriesForm extends ContentEntityForm { */ protected $fieldTypePluginManager; + /** + * The current user. + * + * @var \Drupal\Core\Session\AccountProxyInterface + */ + protected $currentUser; + + /** + * The time service. + * + * @var \Drupal\Component\Datetime\Time + */ + protected $time; + + /** + * The module handler service. + * + * @var \Drupal\Core\Extension\ModuleHandler + */ + protected $moduleHandler; + + /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + /** * {@inheritdoc} */ @@ -87,7 +118,10 @@ class EventSeriesForm extends ContentEntityForm { $container->get('plugin.manager.field.field_type'), $container->get('entity.repository'), $container->get('entity_type.bundle.info'), - $container->get('datetime.time') + $container->get('datetime.time'), + $container->get('current_user'), + $container->get('module_handler'), + $container->get('config.factory') ); } @@ -108,14 +142,30 @@ class EventSeriesForm extends ContentEntityForm { * The entity field manager. * @param \Drupal\Core\Field\FieldTypePluginManager $field_type_plugin_manager * The field type plugin manager. + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository interface. + * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info + * The entity type bundle info interface. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time interface. + * @param \Drupal\Core\Session\AccountProxyInterface $current_user + * The current user. + * @param \Drupal\Core\Extension\ModuleHandler $module_handler + * The module handler service. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The config factory. */ - public function __construct(EventCreationService $creation_service, EntityStorageInterface $storage, EntityManagerInterface $entity_manager, Messenger $messenger, DateFormatter $date_formatter, EntityFieldManager $entity_field_manager, FieldTypePluginManager $field_type_plugin_manager, EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) { + public function __construct(EventCreationService $creation_service, EntityStorageInterface $storage, EntityManagerInterface $entity_manager, Messenger $messenger, DateFormatter $date_formatter, EntityFieldManager $entity_field_manager, FieldTypePluginManager $field_type_plugin_manager, EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, AccountProxyInterface $current_user = NULL, ModuleHandler $module_handler = NULL, ConfigFactory $config_factory = NULL) { $this->creationService = $creation_service; $this->storage = $storage; $this->messenger = $messenger; $this->dateFormatter = $date_formatter; $this->entityFieldManager = $entity_field_manager; $this->fieldTypePluginManager = $field_type_plugin_manager; + $this->time = $time; + $this->currentUser = $current_user; + $this->moduleHandler = $module_handler; + $this->configFactory = $config_factory; parent::__construct($entity_repository, $entity_type_bundle_info, $time); } @@ -125,7 +175,7 @@ class EventSeriesForm extends ContentEntityForm { public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); - $config = \Drupal::config('recurring_events.eventseries.config'); + $config = $this->configFactory->get('recurring_events.eventseries.config'); /* @var $entity \Drupal\recurring_events\Entity\EventSeries */ $entity = $this->entity; @@ -143,7 +193,7 @@ class EventSeriesForm extends ContentEntityForm { // necessary fields from the entity form. $recur_fields = $this->creationService->getRecurFieldTypes(FALSE); $all_recur_fields = $recur_fields; - \Drupal::moduleHandler()->alter('recurring_events_recur_field_types', $recur_fields); + $this->moduleHandler->alter('recurring_events_recur_field_types', $recur_fields); $form['recur_type']['widget']['#options'] = $recur_fields; @@ -226,7 +276,7 @@ class EventSeriesForm extends ContentEntityForm { '#title' => $this->t('Status'), '#attributes' => ['class' => ['entity-meta__header']], '#tree' => TRUE, - '#access' => \Drupal::currentUser()->hasPermission('administer eventseries'), + '#access' => $this->currentUser->hasPermission('administer eventseries'), ]; $form['meta']['published'] = [ '#type' => 'item', @@ -282,24 +332,19 @@ class EventSeriesForm extends ContentEntityForm { */ public function save(array $form, FormStateInterface $form_state) { $entity = $this->getEntity(); - $original = NULL; // Save as a new revision if requested to do so. if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) { $entity->setNewRevision(); // If a new revision is created, save the current user as revision author. - $entity->setRevisionCreationTime(\Drupal::time()->getRequestTime()); - $entity->setRevisionUserId(\Drupal::currentUser()->id()); + $entity->setRevisionCreationTime($this->time->getRequestTime()); + $entity->setRevisionUserId($this->currentUser->id()); } else { $entity->setNewRevision(FALSE); } - if (!$entity->isNew()) { - $original = $this->storage->loadUnchanged($entity->id()); - } - if ($entity->isDefaultTranslation()) { $this->messenger->addStatus($this->t('Successfully saved the %name event series', [ '%name' => $entity->title->value, diff --git a/src/Form/EventSeriesRevisionDeleteForm.php b/src/Form/EventSeriesRevisionDeleteForm.php index 8f33e843..42af67f8 100644 --- a/src/Form/EventSeriesRevisionDeleteForm.php +++ b/src/Form/EventSeriesRevisionDeleteForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Messenger\Messenger; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides a form for deleting an eventseries revision. @@ -18,6 +19,8 @@ use Drupal\Core\Messenger\Messenger; */ class EventSeriesRevisionDeleteForm extends ConfirmFormBase { + use StringTranslationTrait; + /** * The eventseries revision. * @@ -96,7 +99,7 @@ class EventSeriesRevisionDeleteForm extends ConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to delete the revision from %revision-date?', [ + return $this->t('Are you sure you want to delete the revision from %revision-date?', [ '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()), ]); } @@ -112,7 +115,7 @@ class EventSeriesRevisionDeleteForm extends ConfirmFormBase { * {@inheritdoc} */ public function getConfirmText() { - return t('Delete'); + return $this->t('Delete'); } /** diff --git a/src/Form/EventSeriesRevisionRevertForm.php b/src/Form/EventSeriesRevisionRevertForm.php index d216ee14..a26200be 100644 --- a/src/Form/EventSeriesRevisionRevertForm.php +++ b/src/Form/EventSeriesRevisionRevertForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Url; use Drupal\recurring_events\EventInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Messenger\Messenger; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides a form for reverting an eventseries revision. @@ -18,6 +19,8 @@ use Drupal\Core\Messenger\Messenger; */ class EventSeriesRevisionRevertForm extends ConfirmFormBase { + use StringTranslationTrait; + /** * The eventseries revision. * @@ -84,7 +87,7 @@ class EventSeriesRevisionRevertForm extends ConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); + return $this->t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); } /** @@ -98,7 +101,7 @@ class EventSeriesRevisionRevertForm extends ConfirmFormBase { * {@inheritdoc} */ public function getConfirmText() { - return t('Revert'); + return $this->t('Revert'); } /** @@ -127,7 +130,7 @@ class EventSeriesRevisionRevertForm extends ConfirmFormBase { $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision = $this->prepareRevertedRevision($this->revision, $form_state); - $this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]); + $this->revision->revision_log = $this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]); $this->revision->save(); $this->logger('content')->notice('eventseries: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); diff --git a/src/Form/EventSeriesRevisionRevertTranslationForm.php b/src/Form/EventSeriesRevisionRevertTranslationForm.php index 9406fabd..448b3c68 100644 --- a/src/Form/EventSeriesRevisionRevertTranslationForm.php +++ b/src/Form/EventSeriesRevisionRevertTranslationForm.php @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\recurring_events\EventInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Component\Datetime\TimeInterface; /** * Provides form to revert an eventseries revision for a single translation. @@ -30,6 +31,13 @@ class EventSeriesRevisionRevertTranslationForm extends EventSeriesRevisionRevert */ protected $languageManager; + /** + * The time service. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected $time; + /** * Constructs a new EventSeriesRevisionRevertTranslationForm. * @@ -39,10 +47,13 @@ class EventSeriesRevisionRevertTranslationForm extends EventSeriesRevisionRevert * The date formatter service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. */ - public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter, LanguageManagerInterface $language_manager) { + public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter, LanguageManagerInterface $language_manager, TimeInterface $time) { parent::__construct($entity_storage, $date_formatter); $this->languageManager = $language_manager; + $this->time = $time; } /** @@ -52,7 +63,8 @@ class EventSeriesRevisionRevertTranslationForm extends EventSeriesRevisionRevert return new static( $container->get('entity.manager')->getStorage('eventseries'), $container->get('date.formatter'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('datetime.time') ); } @@ -67,7 +79,7 @@ class EventSeriesRevisionRevertTranslationForm extends EventSeriesRevisionRevert * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to revert @language translation to the revision from %revision-date?', ['@language' => $this->languageManager->getLanguageName($this->langcode), '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); + return $this->t('Are you sure you want to revert @language translation to the revision from %revision-date?', ['@language' => $this->languageManager->getLanguageName($this->langcode), '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); } /** @@ -106,7 +118,7 @@ class EventSeriesRevisionRevertTranslationForm extends EventSeriesRevisionRevert $latest_revision_translation->setNewRevision(); $latest_revision_translation->isDefaultRevision(TRUE); - $revision->setRevisionCreationTime(\Drupal::time()->getRequestTime()); + $revision->setRevisionCreationTime($this->time->getRequestTime()); return $latest_revision_translation; } diff --git a/src/Form/EventSeriesSettingsForm.php b/src/Form/EventSeriesSettingsForm.php index 4e7762ac..3e26270c 100644 --- a/src/Form/EventSeriesSettingsForm.php +++ b/src/Form/EventSeriesSettingsForm.php @@ -6,6 +6,8 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\Core\Link; +use Drupal\recurring_events\EventCreationService; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Class EventSeriesSettingsForm. @@ -14,6 +16,32 @@ use Drupal\Core\Link; */ class EventSeriesSettingsForm extends ConfigFormBase { + /** + * The event creation service. + * + * @var \Drupal\recurring_events\EventCreationService + */ + protected $creationService; + + /** + * Constructs a new EventSeriesSettingsForm. + * + * @param \Drupal\recurring_events\EventCreationService $creation_service + * The event creation service. + */ + public function __construct(EventCreationService $creation_service) { + $this->creationService = $creation_service; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('recurring_events.event_creation_service') + ); + } + /** * Returns a unique string identifying the form. * @@ -128,13 +156,13 @@ class EventSeriesSettingsForm extends ConfigFormBase { ]; $days = [ - 'monday' => t('Monday'), - 'tuesday' => t('Tuesday'), - 'wednesday' => t('Wednesday'), - 'thursday' => t('Thursday'), - 'friday' => t('Friday'), - 'saturday' => t('Saturday'), - 'sunday' => t('Sunday'), + 'monday' => $this->t('Monday'), + 'tuesday' => $this->t('Tuesday'), + 'wednesday' => $this->t('Wednesday'), + 'thursday' => $this->t('Thursday'), + 'friday' => $this->t('Friday'), + 'saturday' => $this->t('Saturday'), + 'sunday' => $this->t('Sunday'), ]; $form['creation']['days'] = [ @@ -164,7 +192,7 @@ class EventSeriesSettingsForm extends ConfigFormBase { '#default_value' => $config->get('includes'), ]; - $fields = \Drupal::service('recurring_events.event_creation_service')->getRecurFieldTypes(FALSE); + $fields = $this->creationService->getRecurFieldTypes(FALSE); $form['creation']['enabled_fields'] = [ '#type' => 'checkboxes', diff --git a/src/Form/EventSeriesTypeForm.php b/src/Form/EventSeriesTypeForm.php index 6e0a7ef3..93d1e2d9 100644 --- a/src/Form/EventSeriesTypeForm.php +++ b/src/Form/EventSeriesTypeForm.php @@ -4,12 +4,40 @@ namespace Drupal\recurring_events\Form; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Messenger\Messenger; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Class EventSeriesTypeForm. */ class EventSeriesTypeForm extends EntityForm { + /** + * The messenger service. + * + * @var \Drupal\Core\Messenger\Messenger + */ + protected $messenger; + + /** + * Constructs a new EventSeriesTypeForm. + * + * @param \Drupal\Core\Messenger\Messenger $messenger + * The messenger service. + */ + public function __construct(Messenger $messenger) { + $this->messenger = $messenger; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('messenger') + ); + } + /** * {@inheritdoc} */ @@ -54,13 +82,13 @@ class EventSeriesTypeForm extends EntityForm { switch ($status) { case SAVED_NEW: - \Drupal::messenger()->addMessage($this->t('Created the %label event series type.', [ + $this->messenger->addMessage($this->t('Created the %label event series type.', [ '%label' => $eventseries_type->label(), ])); break; default: - \Drupal::messenger()->addMessage($this->t('Saved the %label event series type.', [ + $this->messenger->addMessage($this->t('Saved the %label event series type.', [ '%label' => $eventseries_type->label(), ])); } diff --git a/src/IncludedDatesHtmlRouteProvider.php b/src/IncludedDatesHtmlRouteProvider.php index 6fe24493..b7bebda5 100644 --- a/src/IncludedDatesHtmlRouteProvider.php +++ b/src/IncludedDatesHtmlRouteProvider.php @@ -4,7 +4,6 @@ namespace Drupal\recurring_events; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; -use Symfony\Component\Routing\Route; /** * Provides routes for Included dates entities. @@ -19,9 +18,6 @@ class IncludedDatesHtmlRouteProvider extends AdminHtmlRouteProvider { */ public function getRoutes(EntityTypeInterface $entity_type) { $collection = parent::getRoutes($entity_type); - - // Provide your custom entity routes here. - return $collection; } diff --git a/src/Plugin/Field/FieldFormatter/EventInstanceDateFormatter.php b/src/Plugin/Field/FieldFormatter/EventInstanceDateFormatter.php index 0d9d34be..c948f530 100644 --- a/src/Plugin/Field/FieldFormatter/EventInstanceDateFormatter.php +++ b/src/Plugin/Field/FieldFormatter/EventInstanceDateFormatter.php @@ -9,6 +9,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Url; use Drupal\Core\Link; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Plugin implementation of the 'recurring events eventinstance date' formatter. @@ -24,6 +25,8 @@ use Drupal\Core\Link; */ class EventInstanceDateFormatter extends EntityReferenceFormatterBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -40,7 +43,7 @@ class EventInstanceDateFormatter extends EntityReferenceFormatterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $elements['link'] = [ - '#title' => t('Link date to the referenced entity'), + '#title' => $this->t('Link date to the referenced entity'), '#type' => 'checkbox', '#default_value' => $this->getSetting('link'), ]; @@ -50,7 +53,7 @@ class EventInstanceDateFormatter extends EntityReferenceFormatterBase { $elements['date_format'] = [ '#type' => 'textfield', - '#title' => t('Date Format @link', [ + '#title' => $this->t('Date Format @link', [ '@link' => $php_date_link->toString(), ]), '#required' => TRUE, @@ -58,9 +61,9 @@ class EventInstanceDateFormatter extends EntityReferenceFormatterBase { ]; $elements['separator'] = [ - '#title' => t('Separator'), + '#title' => $this->t('Separator'), '#type' => 'textfield', - '#description' => t('Enter the separator to use between start and end dates.'), + '#description' => $this->t('Enter the separator to use between start and end dates.'), '#default_value' => $this->getSetting('separator'), ]; @@ -72,11 +75,11 @@ class EventInstanceDateFormatter extends EntityReferenceFormatterBase { */ public function settingsSummary() { $summary = []; - $summary[] = $this->getSetting('link') ? t('Link to the referenced entity') : t('No link'); - $summary[] = t('Format: %format', [ + $summary[] = $this->getSetting('link') ? $this->t('Link to the referenced entity') : $this->t('No link'); + $summary[] = $this->t('Format: %format', [ '%format' => $this->getSetting('date_format'), ]); - $summary[] = t('Separator: %separator', [ + $summary[] = $this->t('Separator: %separator', [ '%separator' => $this->getSetting('separator'), ]); return $summary; diff --git a/src/Plugin/Field/FieldType/ConsecutiveRecurringDate.php b/src/Plugin/Field/FieldType/ConsecutiveRecurringDate.php index 9b0cd3f0..5b001517 100644 --- a/src/Plugin/Field/FieldType/ConsecutiveRecurringDate.php +++ b/src/Plugin/Field/FieldType/ConsecutiveRecurringDate.php @@ -138,7 +138,6 @@ class ConsecutiveRecurringDate extends DateRangeItem implements RecurringEventsF $config = []; $user_timezone = new \DateTimeZone(date_default_timezone_get()); - $utc_timezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE); $user_input = $form_state->getUserInput(); if (!empty($user_input['consecutive_recurring_date'][0]['value']['date']) @@ -239,7 +238,7 @@ class ConsecutiveRecurringDate extends DateRangeItem implements RecurringEventsF * {@inheritdoc} */ public static function calculateInstances(array $form_data) { - $dates = $events_to_create = []; + $events_to_create = []; $utc_timezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE); $daily_dates = static::findDailyDatesBetweenDates($form_data['start_date'], $form_data['end_date']); diff --git a/src/Plugin/Field/FieldType/DailyRecurringDate.php b/src/Plugin/Field/FieldType/DailyRecurringDate.php index 66b67277..5917817d 100644 --- a/src/Plugin/Field/FieldType/DailyRecurringDate.php +++ b/src/Plugin/Field/FieldType/DailyRecurringDate.php @@ -92,7 +92,6 @@ class DailyRecurringDate extends DateRangeItem implements RecurringEventsFieldTy $config = []; $user_timezone = new \DateTimeZone(date_default_timezone_get()); - $utc_timezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE); $user_input = $form_state->getUserInput(); $time = $user_input['daily_recurring_date'][0]['time']; @@ -157,7 +156,7 @@ class DailyRecurringDate extends DateRangeItem implements RecurringEventsFieldTy * {@inheritdoc} */ public static function calculateInstances(array $form_data) { - $dates = $events_to_create = []; + $events_to_create = []; $utc_timezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE); $daily_dates = static::findDailyDatesBetweenDates($form_data['start_date'], $form_data['end_date']); diff --git a/src/Plugin/Field/FieldType/MonthlyRecurringDate.php b/src/Plugin/Field/FieldType/MonthlyRecurringDate.php index f65e6625..e2875909 100644 --- a/src/Plugin/Field/FieldType/MonthlyRecurringDate.php +++ b/src/Plugin/Field/FieldType/MonthlyRecurringDate.php @@ -116,7 +116,6 @@ class MonthlyRecurringDate extends WeeklyRecurringDate implements RecurringEvent $config = []; $user_timezone = new \DateTimeZone(date_default_timezone_get()); - $utc_timezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE); $user_input = $form_state->getUserInput(); $time = $user_input['monthly_recurring_date'][0]['time']; diff --git a/src/Plugin/Field/FieldType/WeeklyRecurringDate.php b/src/Plugin/Field/FieldType/WeeklyRecurringDate.php index 455a10c7..ef29a5ff 100644 --- a/src/Plugin/Field/FieldType/WeeklyRecurringDate.php +++ b/src/Plugin/Field/FieldType/WeeklyRecurringDate.php @@ -81,7 +81,6 @@ class WeeklyRecurringDate extends DailyRecurringDate implements RecurringEventsF $config = []; $user_timezone = new \DateTimeZone(date_default_timezone_get()); - $utc_timezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE); $user_input = $form_state->getUserInput(); $time = $user_input['weekly_recurring_date'][0]['time']; -- GitLab