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