BundleEntityFormBase.php 1000 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. /**
  4. * Class BundleEntityFormBase is a base form for bundle config entities.
  5. */
  6. class BundleEntityFormBase extends EntityForm {
  7. /**
  8. * Protects the bundle entity's ID property's form element against changes.
  9. *
  10. * This method is assumed to be called on a completely built entity form,
  11. * including a form element for the bundle config entity's ID property.
  12. *
  13. * @param array $form
  14. * The completely built entity bundle form array.
  15. *
  16. * @return array
  17. * The updated entity bundle form array.
  18. */
  19. protected function protectBundleIdElement(array $form) {
  20. $entity = $this->getEntity();
  21. $id_key = $entity->getEntityType()->getKey('id');
  22. assert(isset($form[$id_key]));
  23. $element = &$form[$id_key];
  24. // Make sure the element is not accidentally re-enabled if it has already
  25. // been disabled.
  26. if (empty($element['#disabled'])) {
  27. $element['#disabled'] = !$entity->isNew();
  28. }
  29. return $form;
  30. }
  31. }