translation/ConfigEntityMapper.php
<?php
/**
* @file
* Contains \Drupal\config_translation\ConfigEntityMapper.
*/
namespace Drupal\config_translation;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\locale\LocaleConfigManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Configuration entity mapper.
*/
class ConfigEntityMapper extends ConfigNamesMapper {
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
/**
* Configuration entity type name.
*
* @var string
*/
protected $entityType;
/**
* Loaded entity instance to help produce the translation interface.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $entity;
/**
* The label for the entity type.
*
* @var string
*/
protected $typeLabel;
/**
* Constructs a ConfigEntityMapper.
*
* @param string $plugin_id
* The config mapper plugin ID.
* @param array $plugin_definition
* An array of definitions with mapper details.
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The configuration factory.
* @param \Drupal\locale\LocaleConfigManager $locale_config_manager
* The locale configuration manager.
* @param \Drupal\config_translation\ConfigMapperManagerInterface $config_mapper_manager
* The mapper plugin discovery service.
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager
* The string translation manager.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
*/
public ConfigFactory ConfigMapperManagerInterface TranslationInterface
parent
entityManager
// Field instances are grouped by the entity type they are attached to.
// Create a useful label from the entity type they are attached to.
entityManager
typeLabel
}
}
/**
* {@inheritdoc}
*/
public static ContainerInterface
// Note that we ignore the plugin $configuration because mappers have
// nothing to configure in themselves.
);
}
/**
* {@inheritdoc}
*/
public Request $request) {
attributesentityType);
}
/**
* 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\Entity\EntityInterface $entity
* The entity to set.
*
* @return bool
* TRUE, if the entity was set successfully; FALSE otherwise.
*/
public EntityInterface $entity) {
entity)) {
return FALSE;
}
entity
// Replace title placeholder with entity label. It is later escaped for
// display.
pluginDefinition
// Add the list of configuration IDs belonging to this entity. We add on a
// possibly existing list of names. This allows modules to alter the entity
// page with more names if form altering added more configuration to an
// entity. This is not a Drupal 8 best practice (ideally the configuration
// would have pluggable components), but this may happen as well.
entityManagerentityType);
.
return TRUE;
}
/**
* {@inheritdoc}
*/
public
entityType 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
* The entity type to set.
*
* @return bool
* TRUE if the entity type was set correctly; FALSE otherwise.
*/
public
entityType)) {
return FALSE;
}
entityType
return TRUE;
}
/**
* Gets the entity type from this mapper.
*
* @return string
*/
public function getType() {
entityType;
}
/**
* {@inheritdoc}
*/
public
entityManagerentityType);
}
/**
* {@inheritdoc}
*/
public
// The typeLabel is used to override the default entity type label in
// configuration translation UI. It is used to distinguish field instances
// from each other, but also can easily override in other mapper
// implementations.
typeLabel)) {
typeLabel;
}
entityManagerentityType);
}
/**
* {@inheritdoc}
*/
public
.
),
);
}
/**
* {@inheritdoc}
*/
public
// @todo taking the group name from the mapper is not contrib scalable
// (maybe not even core). See
// https://drupal.org/node/2084463#comment-8156943 Also the same problem
// in core Views for now.
entityType) {
case 'menu':
case 'block':
entityType;
case 'view':
default:
return NULL;
}
}
}