diff --git a/recurring_events.module b/recurring_events.module index b7d5a92e4ad666246414a96b1ff884a864fed5cd..7c630bd957710cf0dd14ae11fdef928bfb060eec 100644 --- a/recurring_events.module +++ b/recurring_events.module @@ -65,6 +65,9 @@ function recurring_events_entity_base_field_info_alter(&$fields, EntityTypeInter ->setClass($class) ->setSettings($settings) ->setTargetEntityTypeId($entity_type->id()) + ->setTranslatable(FALSE) + ->setRevisionable(FALSE) + ->setReadOnly(TRUE) ->setDisplayConfigurable('view', TRUE); } } diff --git a/src/Entity/FieldInheritance.php b/src/Entity/FieldInheritance.php index 6e94ca6ba167f365e95cf4145c30bc95a085e6ac..a136b4b41cc159315dc7231b3304a2d9b445a98d 100644 --- a/src/Entity/FieldInheritance.php +++ b/src/Entity/FieldInheritance.php @@ -18,9 +18,6 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; * "edit" = "Drupal\recurring_events\Form\FieldInheritanceForm", * "delete" = "Drupal\recurring_events\Form\FieldInheritanceDeleteForm" * }, - * "route_provider" = { - * "html" = "Drupal\recurring_events\FieldInheritanceHtmlRouteProvider", - * }, * }, * config_prefix = "field_inheritance", * admin_permission = "administer site configuration", diff --git a/src/FieldInheritanceHtmlRouteProvider.php b/src/FieldInheritanceHtmlRouteProvider.php deleted file mode 100644 index dd0fba9ebdcad329ca3195296f0d61a88ca6942b..0000000000000000000000000000000000000000 --- a/src/FieldInheritanceHtmlRouteProvider.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace Drupal\recurring_events; - -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; -use Symfony\Component\Routing\Route; - -/** - * Provides routes for Field inheritance entities. - * - * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider - * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider - */ -class FieldInheritanceHtmlRouteProvider extends AdminHtmlRouteProvider { - - /** - * {@inheritdoc} - */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = parent::getRoutes($entity_type); - - // Provide your custom entity routes here. - - return $collection; - } - -} diff --git a/src/Plugin/FieldInheritance/FieldInheritancePluginBase.php b/src/Plugin/FieldInheritance/FieldInheritancePluginBase.php index c0e0fc9fcaec6cb1a146c7ed8acc2d0f029af786..b347656d361b2a22ec4754e6375c33f32d4a3536 100644 --- a/src/Plugin/FieldInheritance/FieldInheritancePluginBase.php +++ b/src/Plugin/FieldInheritance/FieldInheritancePluginBase.php @@ -5,11 +5,14 @@ namespace Drupal\recurring_events\Plugin\FieldInheritance; use Drupal\Component\Plugin\PluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\recurring_events\FieldInheritancePluginInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Entity\EntityInterface; /** * Abstract class FieldInheritancePluginBase. */ -abstract class FieldInheritancePluginBase extends PluginBase implements FieldInheritancePluginInterface { +abstract class FieldInheritancePluginBase extends PluginBase implements FieldInheritancePluginInterface, ContainerFactoryPluginInterface { /** * The entity. @@ -39,6 +42,20 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh */ protected $entityField; + /** + * The language manager service. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** + * The current language code. + * + * @var string + */ + protected $langCode; + /** * Constructs a FieldInheritancePluginBase object. * @@ -48,8 +65,10 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh * The plugin ID. * @param mixed $plugin_definition * The plugin definition. + * @param Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entity = $configuration['entity']; $this->method = $configuration['method']; @@ -57,6 +76,8 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh if (!empty($configuration['entity field'])) { $this->entityField = $configuration['entity field']; } + $this->languageManager = $language_manager; + $this->langCode = $this->languageManager->getCurrentLanguage()->getId(); } /** @@ -66,7 +87,8 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh return new static( $configuration, $plugin_id, - $plugin_definition + $plugin_definition, + $container->get('language_manager') ); } @@ -126,7 +148,7 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh * The inherited data. */ protected function inheritData() { - $series = $this->entity->getEventSeries(); + $series = $this->getEventSeries(); return $series->{$this->getSourceField()}->getValue() ?? ''; } @@ -137,8 +159,8 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh * The prepended data. */ protected function prependData() { - $series = $this->entity->getEventSeries(); - $instance = $this->entity; + $series = $this->getEventSeries(); + $instance = $this->getEventInstance(); $values = []; if (!empty($instance->{$this->getEntityField()}->getValue())) { @@ -157,8 +179,8 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh * The appended data. */ protected function appendData() { - $series = $this->entity->getEventSeries(); - $instance = $this->entity; + $series = $this->getEventSeries(); + $instance = $this->getEventInstance(); $values = []; if (!empty($series->{$this->getSourceField()}->getValue())) { @@ -177,8 +199,8 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh * The fallback data. */ protected function fallbackData() { - $series = $this->entity->getEventSeries(); - $instance = $this->entity; + $series = $this->getEventSeries(); + $instance = $this->getEventInstance(); if (!empty($instance->{$this->getEntityField()}->getValue())) { $values = $instance->{$this->getEntityField()}->getValue(); @@ -217,4 +239,31 @@ abstract class FieldInheritancePluginBase extends PluginBase implements FieldInh return TRUE; } + /** + * Get the translated eventseries entity. + * + * @return Drupal\Core\Entity\EntityInterface + * The translated eventseries entity. + */ + protected function getEventSeries() { + $series = $this->entity->getEventSeries(); + if ($series->hasTranslation($this->langCode)) { + return $series->getTranslation($this->langCode); + } + return $series; + } + + /** + * Get the translated eventinstance entity. + * + * @return Drupal\Core\Entity\EntityInterface + * The translated eventinstance entity. + */ + protected function getEventInstance() { + if ($this->entity->hasTranslation($this->langCode)) { + return $this->entity->getTranslation($this->langCode); + } + return $this->entity; + } + }