Same name in other branches
- 2.x src/EntityClone/Config/ConfigEntityCloneFormBase.php \Drupal\entity_clone\EntityClone\Config\ConfigEntityCloneFormBase::formElement()
Overrides EntityCloneFormInterface::formElement
1 method overrides ConfigEntityCloneFormBase::formElement()
- MenuEntityCloneForm::formElement dans src/
EntityClone/ Config/ MenuEntityCloneForm.php - Get all specific form element.
Fichier
-
src/
EntityClone/ Config/ ConfigEntityCloneFormBase.php, line 59
Classe
- ConfigEntityCloneFormBase
- Class Config Entity Clone FormBase.
Namespace
Drupal\entity_clone\EntityClone\ConfigCode
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;
}