You are here

public function EckEntityTypeEditForm::buildForm in Entity Construction Kit (ECK) 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EckEntityTypeFormBase::buildForm

File

src/Form/EntityType/EckEntityTypeEditForm.php, line 28

Class

EckEntityTypeEditForm
Provides the edit form for ECK Entity Type.

Namespace

Drupal\eck\Form\EntityType

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);

  /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $fieldStorage */
  $fieldStorage = $this->entityTypeManager
    ->getStorage($this->entity
    ->id());

  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $efm */
  $definitions = $this->entityFieldManager
    ->getBaseFieldDefinitions($this->entity
    ->id());
  foreach ([
    'title',
    'created',
    'changed',
    'uid',
    'status',
  ] as $field) {

    // Lock entity base field configuration in case when that field already
    // contain some data.
    if (isset($definitions[$field]) && $fieldStorage
      ->countFieldData($definitions[$field], TRUE)) {
      $form['base_fields'][$field]['#disabled'] = TRUE;
    }
  }
  return $form;
}