diff --git a/config/install/recurring_events.eventseries_type.default.yml b/config/install/recurring_events.eventseries_type.default.yml index e1b9ee50b1c73085d75c5c0d910f7b43c304580a..f3865a6e07eb41be1599329318eb21a13e50ed1a 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 ade58157bc2f1fd55a18ddd5244dc638d52f910a..fdfadb85cb5211d621c3c5b446ded79d737595b4 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 ff596636b5c69f9d28e4f3b3dfc0b6946e367319..9b534c83e430b2b90e4bdf3741f8fd2bb462baef 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 1f4c1a06ea338a2387de713edeb8e1ffc5c6bbb1..b4dfdf04a59dd3ed2c74fc7cbe51afdd89d93a65 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 79e065dfe9371ee747907971159c2e413feb1922..6950c953fd7aabd90b841c10333872f6ca90bc8b 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 6b2b43ba4b723161ee0ca3a7100a14aa98434871..b305b87fc5d93e419702acf665607bab56b36806 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 43ce6ea47aefe5fa4be6fc80012896ff0badbe26..76e212749bea2864d75e1bc0e1ba3dfa9496db93 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 b603337a2b489e9b4e563b588b6676a40dc1f533..e23c6d1f61c374d1bbef0bccebb34c049a9e46d3 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 4e599cb467b07c0842557ed6d3f28823d3c95287..41b953f28323dec97a740195de625ee97094886d 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 14c5af952d15aeba7b2a31956a0079dab8ecf5bf..54c153a814c432e103d79c3098d569b7c25d958d 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 572f3efcdffe692fb7b912eeff52dfbccb8e6129..729d3da772d701d0fa6f7bf8a17b211160611c39 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 992583d8fdae346af023b2aebafe7f166a433db4..66d9b258dabc611aca7dbdf54c04ca403a93e1a2 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 5cf22772c0b6b6e6a4e86f9ea8d074132ccdd162..1d42c64ef37188b2c2c4a418a016efd841df3c8a 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 6644e0c5c860aba7c11f6ef6cc5323a182b9a784..73df63b123f3386e6717ef4a162d3e306ac45529 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 8960f2c24a7601c8d9c9fb2366d3e71adf9e7e62..f2cf604d0c54bc00d033e33d0c25747986b5529f 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 edc38c0c08abe5b694d86f1e1b0e5d0f5d59227e..2699611302237721fd141a891e4e518f8655bf2a 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 ce3a1b770ecfc0cdb1fcb084eb1e4c444cdb605f..970638714715235c5e45ea90072de2d7435efb3c 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 b67b92ad2cafba73102aa18edd441b78095d4796..fea21b46e19b3ecc7699905b876ddf7557d8ef9d 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 87ee9b8574f85d89723410646f0b676921e6090a..7eba0789807bd569c4813ca49ae9e92cb5dc6cc9 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 c349d2c33a6f1646c145675db7f4deaec586e436..10f02f6e37af89d86f866867609df1bd3f622d8f 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 32b513d80d5cb28883c4fc83f2823929d444078d..0c9d369df868a0d615b6f6cea73b026e29cab692 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 cce0bd77646c2b41012986681549d28810923c30..6e02c4c35d53f92e3b09d7de2610d2418927d992 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 8f33e84364520cd309d1a000f31034b919e78da2..42af67f8f773b01e0321ead938ab56bfcefeef6e 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 d216ee14f7c0a844ca826ecca6816cfc5cb07232..a26200beb8ccb21549a437f4a2cf6d2974c859d7 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 9406fabda8f70c78ab1f09e12a6bc0a30c595f18..448b3c681de8bc7573ead0331e5454200bf56fb7 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 4e7762ac4546b2dc87d82e6875b64297d3001468..3e26270c4ef6c879e80b882066d19714837c1063 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 6e0a7ef3eb8620993486fa7b2416a2602b2d5e98..93d1e2d9f87b74bb29c60a65909a06cee0a007fc 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 6fe244930c006464a403442b921f41be653267ad..b7bebda5863dca844bcbadf792b8c67084076f4a 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 0d9d34be7862893ad80317a4ccb6cee140cd2b06..c948f530009b6f695afa558a4692cd7fdc66bdb6 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 9b0cd3f0c566d803f99e8855b9d730f6dfc118dd..5b001517dd3c09d80ba05033dee3db16d7393492 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 66b67277d369c7e5194ab21f462cd640f7517898..5917817d55c4dbb4ac34cda7be6f5d22aa71f5ae 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 f65e6625a3471b71108a3e883d7c1ddeca9d2817..e28759093241c7e729273a5fe35b9ee93272520a 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 455a10c7337299a2ef2dc372ef797b4bfab9d3ef..ef29a5ff60a32a89b6426fd56f6e8f4c4a49c001 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'];