Verified Commit 49e0f8b6 authored by Dave Long's avatar Dave Long
Browse files

Issue #2653652 by vasike, tstoeckler, penyaskito, Daniel_Rempe, catch, Gábor...

Issue #2653652 by vasike, tstoeckler, penyaskito, Daniel_Rempe, catch, Gábor Hojtsy, smustgrave, maxocub, alexpott, Kristen Pol: Create an interface for ConfigEntityMapper
parent c61764be
Loading
Loading
Loading
Loading
+8 −37
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
/**
 * Configuration mapper for configuration entities.
 */
class ConfigEntityMapper extends ConfigNamesMapper {
class ConfigEntityMapper extends ConfigNamesMapper implements ConfigEntityMapperInterface {

  /**
   * The entity type manager.
@@ -115,29 +115,14 @@ public function populateFromRouteMatch(RouteMatchInterface $route_match) {
  }

  /**
   * Gets the entity instance for this mapper.
   *
   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface
   *   The configuration entity.
   * {@inheritdoc}
   */
  public function getEntity() {
    return $this->entity;
  }

  /**
   * Sets the entity instance for this mapper.
   *
   * This method can only be invoked when the concrete entity is known, that is
   * in a request for an entity translation path. After this method is called,
   * the mapper is fully populated with the proper display title and
   * configuration names to use to check permissions or display a translation
   * screen.
   *
   * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
   *   The configuration entity to set.
   *
   * @return bool
   *   TRUE, if the entity was set successfully; FALSE otherwise.
   * {@inheritdoc}
   */
  public function setEntity(ConfigEntityInterface $entity) {
    if (isset($this->entity)) {
@@ -173,34 +158,20 @@ public function getBaseRouteParameters() {
  }

  /**
   * Set entity type for this mapper.
   *
   * This should be set in initialization. A mapper that knows its type but
   * not yet its names is still useful for router item and tab generation. The
   * concrete entity only turns out later with actual controller invocations,
   * when the setEntity() method is invoked before the rest of the methods are
   * used.
   *
   * @param string $entity_type
   *   The entity type to set.
   *
   * @return bool
   *   TRUE if the entity type was set correctly; FALSE otherwise.
   * {@inheritdoc}
   */
  public function setType($entity_type) {
  public function setType(string $entity_type_id): bool {
    if (isset($this->entityType)) {
      return FALSE;
    }
    $this->entityType = $entity_type;
    $this->entityType = $entity_type_id;
    return TRUE;
  }

  /**
   * Gets the entity type from this mapper.
   *
   * @return string
   * {@inheritdoc}
   */
  public function getType() {
  public function getType(): string {
    return $this->entityType;
  }

+62 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\config_translation;

use Drupal\Core\Config\Entity\ConfigEntityInterface;

/**
 * Defines an interface for configuration entity mappers.
 */
interface ConfigEntityMapperInterface extends ConfigMapperInterface {

  /**
   * Gets the entity instance for this mapper.
   *
   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface
   *   The configuration entity.
   */
  public function getEntity();

  /**
   * Sets the entity instance for this mapper.
   *
   * This method can only be invoked when the concrete entity is known, that is
   * in a request for an entity translation path. After this method is called,
   * the mapper is fully populated with the proper display title and
   * configuration names to use to check permissions or display a translation
   * screen.
   *
   * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
   *   The configuration entity to set.
   *
   * @return bool
   *   TRUE, if the entity was set successfully; FALSE otherwise.
   */
  public function setEntity(ConfigEntityInterface $entity);

  /**
   * Set entity type for this mapper.
   *
   * This should be set in initialization. A mapper that knows its type but
   * not yet its names is still useful for router item and tab generation. The
   * concrete entity only turns out later with actual controller invocations,
   * when the setEntity() method is invoked before the rest of the methods are
   * used.
   *
   * @param string $entity_type_id
   *   The entity type ID to set.
   *
   * @return bool
   *   TRUE if the entity type ID was set correctly; FALSE otherwise.
   */
  public function setType(string $entity_type_id): bool;

  /**
   * Gets the entity type ID from this mapper.
   *
   * @return string
   *   The entity type ID.
   */
  public function getType(): string;

}
+2 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

namespace Drupal\editor\EventSubscriber;

use Drupal\config_translation\ConfigEntityMapper;
use Drupal\config_translation\ConfigEntityMapperInterface;
use Drupal\config_translation\Event\ConfigMapperPopulateEvent;
use Drupal\config_translation\Event\ConfigTranslationEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -49,7 +49,7 @@ public static function getSubscribedEvents(): array {
   */
  public function addConfigNames(ConfigMapperPopulateEvent $event) {
    $mapper = $event->getMapper();
    if ($mapper instanceof ConfigEntityMapper && $mapper->getType() == 'filter_format') {
    if ($mapper instanceof ConfigEntityMapperInterface && $mapper->getType() == 'filter_format') {
      $editor_config_name = 'editor.editor.' . $mapper->getEntity()->id();
      // Only add the text editor config if it exists, otherwise we assume no
      // editor has been set for this text format.