public function ConfigEntityCloneFormBase::formElement in Entity Clone 8
Get all specific form element.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity.
bool $parent: Is the parent form element.
Return value
array The form elements.
Overrides EntityCloneFormInterface::formElement
1 call to ConfigEntityCloneFormBase::formElement()
- MenuEntityCloneForm::formElement in src/
EntityClone/ Config/ MenuEntityCloneForm.php - Get all specific form element.
1 method overrides ConfigEntityCloneFormBase::formElement()
- MenuEntityCloneForm::formElement in src/
EntityClone/ Config/ MenuEntityCloneForm.php - Get all specific form element.
File
- src/
EntityClone/ Config/ ConfigEntityCloneFormBase.php, line 60
Class
- ConfigEntityCloneFormBase
- Class ConfigEntityCloneFormBase.
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;
}