You are here

public function BackgroundImageManager::prepareEntityForm in Background Image 8

Same name and namespace in other branches
  1. 2.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::prepareEntityForm()
  2. 2.0.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::prepareEntityForm()

Acts on an entity object about to be shown on an entity form.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity that is about to be shown on the form.

$operation: The current operation.

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

Overrides BackgroundImageManagerInterface::prepareEntityForm

File

src/BackgroundImageManager.php, line 692

Class

BackgroundImageManager

Namespace

Drupal\background_image

Code

public function prepareEntityForm(EntityInterface $entity, $operation, FormStateInterface $form_state) {

  // Only continue if the necessary conditions are met. Views, while valid
  // entities, cannot be embedded. They must be handled in a special way.
  if ($entity
    ->bundle() === 'view' || !$this
    ->validEntity($entity) || !($operation === 'default' || $operation === 'add' || $operation === 'edit')) {
    return;
  }

  // Add the entity as a special key in the form state to indicate that
  // the form should be altered by Background Image.
  $form_state
    ->set('inline_entity_form_entity', $entity);
}