You are here

public function ComponentFormBase::setEntity in Module Builder 8.3

Sets the form entity.

Sets the form entity which will be used for populating form element defaults. Usually, the form entity gets updated by \Drupal\Core\Entity\EntityFormInterface::submit(), however this may be used to completely exchange the form entity, e.g. when preparing the rebuild of a multi-step form.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the current form should operate upon.

Return value

$this

Overrides EntityForm::setEntity

File

src/Form/ComponentFormBase.php, line 67

Class

ComponentFormBase
Base class for Module Builder component forms.

Namespace

Drupal\module_builder\Form

Code

public function setEntity(EntityInterface $entity) {
  parent::setEntity($entity);

  // Get the component data info based on the entity type. This is the
  // earliest we can do this, as entity forms don't know the entity type they
  // are for when constructed.
  $component_type = $entity
    ->getComponentType();
  try {
    $generate_task = $this->codeBuilder
      ->getTask('Generate', $component_type);
  } catch (SanityException $e) {
    $this->sanityException = $e;
    return $this;
  }
  $this
    ->setGenerateTask($generate_task);
  return $this;
}