You are here

public static function BackgroundImageFormTrait::initSubform in Background Image 8

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

Retrieves existing instance or creates new one from form state.

Parameters

array $complete_form: The complete form render array.

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

Return value

self

File

src/BackgroundImageFormTrait.php, line 474

Class

BackgroundImageFormTrait
Trait BackgroundImageFormTrait.

Namespace

Drupal\background_image

Code

public static function initSubform(array &$complete_form, FormStateInterface $form_state) {

  /** @var self $self */
  $self = $form_state
    ->get(self::class);
  if (!$self) {
    $self = new self();
    $form_state
      ->set(self::class, $self);
  }
  if ($self->subform) {
    $subform = NestedArray::getValue($complete_form, $self->subform['#parents'], $exists);
    if ($exists && $subform) {
      $self
        ->setSubform($subform);
    }
  }
  return $self
    ->setForm($complete_form)
    ->setFormState($form_state);
}