class ConfigEntityCloneFormBase in Entity Clone 8
Class ConfigEntityCloneFormBase.
Hierarchy
- class \Drupal\entity_clone\EntityClone\Config\ConfigEntityCloneFormBase implements EntityHandlerInterface, EntityCloneFormInterface
Expanded class hierarchy of ConfigEntityCloneFormBase
1 file declares its use of ConfigEntityCloneFormBase
- entity_clone.module in ./
entity_clone.module - Contains entity_clone.module.
File
- src/
EntityClone/ Config/ ConfigEntityCloneFormBase.php, line 18
Namespace
Drupal\entity_clone\EntityClone\ConfigView source
class ConfigEntityCloneFormBase implements EntityHandlerInterface, EntityCloneFormInterface {
/**
* The string translation.
*
* @var \Drupal\Core\StringTranslation\TranslationManager
*/
protected $translationManager;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new ConfigEntityCloneFormBase.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationManager $translation_manager
* The string translation manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationManager $translation_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->translationManager = $translation_manager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($container
->get('entity_type.manager'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function formElement(EntityInterface $entity, $parent = TRUE) {
$form = [];
if ($this->entityTypeManager
->getDefinition($entity
->getEntityTypeId())
->getKey('label')) {
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->translationManager
->translate('New Label'),
'#maxlength' => 255,
'#required' => TRUE,
];
}
// In common casse, config entities IDs are limited to 64 characters ...
$max_length = 64;
if ($entity
->getEntityType()
->getBundleOf()) {
// ... Except for bundle definition, that are limited to 32 characters.
$max_length = EntityTypeInterface::BUNDLE_MAX_LENGTH;
}
$form['id'] = [
'#type' => 'machine_name',
'#title' => $this->translationManager
->translate('New Id'),
'#maxlength' => $max_length,
'#required' => TRUE,
];
// If entity must have a prefix
// (e.g. entity_form_mode, entity_view_mode, ...).
if (method_exists($entity, 'getTargetType')) {
$form['id']['#field_prefix'] = $entity
->getTargetType() . '.';
}
if (method_exists($entity, 'load')) {
$form['id']['#machine_name'] = [
'exists' => get_class($entity) . '::load',
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function getValues(FormStateInterface $form_state) {
// If entity must have a prefix
// (e.g. entity_form_mode, entity_view_mode, ...).
$field_prefix = '';
if (isset($form_state
->getCompleteForm()['id']['#field_prefix'])) {
$field_prefix = $form_state
->getCompleteForm()['id']['#field_prefix'];
}
return [
'id' => $field_prefix . $form_state
->getValue('id'),
'label' => $form_state
->getValue('label'),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityCloneFormBase:: |
protected | property | The entity type manager. | |
ConfigEntityCloneFormBase:: |
protected | property | The string translation. | |
ConfigEntityCloneFormBase:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
ConfigEntityCloneFormBase:: |
public | function |
Get all specific form element. Overrides EntityCloneFormInterface:: |
1 |
ConfigEntityCloneFormBase:: |
public | function |
Get all new values provided by the specific form element. Overrides EntityCloneFormInterface:: |
|
ConfigEntityCloneFormBase:: |
public | function | Constructs a new ConfigEntityCloneFormBase. |