You are here

public function ConfigPagesForm::configPagesImportValues in Config Pages 8

Same name and namespace in other branches
  1. 8.3 src/ConfigPagesForm.php \Drupal\config_pages\ConfigPagesForm::configPagesImportValues()
  2. 8.2 src/ConfigPagesForm.php \Drupal\config_pages\ConfigPagesForm::configPagesImportValues()

Form submit.

Import other context submit callback.

File

src/ConfigPagesForm.php, line 201

Class

ConfigPagesForm
Form controller for the custom config page edit forms.

Namespace

Drupal\config_pages

Code

public function configPagesImportValues(array $form, FormStateInterface $form_state) {
  $entity = $this->entity;
  if ($imported_entity_id = $form_state
    ->getValue('other_context')['list']) {
    $entityStorage = $this->entityTypeManager
      ->getStorage('config_pages');
    $imported_entity = $entityStorage
      ->load($imported_entity_id);
    foreach ($entity as $name => &$value) {

      // Process only fields added from BO.
      if ($value
        ->getFieldDefinition() instanceof FieldConfigInterface) {
        $entity
          ->set($name, $imported_entity
          ->get($name)
          ->getValue());
      }
    }
    $entity
      ->save();
  }
}