updateFromStorageRecord example

$original_display_config_data = $active_config_storage->read('core.entity_view_display.node.bundle_with_section_field.default');
    /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_view_display_storage */
    $entity_view_display_storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display');
    $entity_view_display = $entity_view_display_storage->load('node.bundle_with_section_field.default');

    $expected_save_message = 'The layout has been saved.';
    foreach (static::FORM_BLOCK_LABELS as $label) {
      $this->addFormBlock($label, "$field_ui_prefix/display/default", $expected_save_message);
      // Revert the entity view display back to remove the previously added form       // block.       $entity_view_display = $entity_view_display_storage
        ->updateFromStorageRecord($entity_view_display$original_display_config_data);
      $entity_view_display->save();
    }
  }

  /** * Tests blocks containing forms can be successfully saved editing overrides. */
  public function testAddingFormBlocksToOverrides() {
    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));
/** * {@inheritdoc} */
  public function importUpdate($name, Config $new_config, Config $old_config) {
    $id = static::getIDFromConfigName($name$this->entityType->getConfigPrefix());
    $entity = $this->load($id);
    if (!$entity) {
      throw new ConfigImporterException("Attempt to update non-existing entity '$id'.");
    }
    $entity->setSyncing(TRUE);
    $entity = $this->updateFromStorageRecord($entity$new_config->get());
    $entity->save();
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function importDelete($name, Config $new_config, Config $old_config) {
    $id = static::getIDFromConfigName($name$this->entityType->getConfigPrefix());
    $entity = $this->load($id);
    $entity->setSyncing(TRUE);
    

        /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_storage */
        $entity_storage = $this->configManager
          ->getEntityTypeManager()
          ->getStorage($entity_type);

        $id = $entity_storage->getIDFromConfigName($name$entity_storage->getEntityType()->getConfigPrefix());
        // It is possible that secondary writes can occur during configuration         // creation. Updates of such configuration are allowed.         if ($this->getActiveStorages($collection)->exists($name)) {
          $entity = $entity_storage->load($id);
          $entity = $entity_storage->updateFromStorageRecord($entity$new_config->get());
        }
        else {
          $entity = $entity_storage->createFromStorageRecord($new_config->get());
        }
        if ($entity->isInstallable()) {
          $entity->trustData()->save();
          if ($id !== $entity->id()) {
            trigger_error(sprintf('The configuration name "%s" does not match the ID "%s"', $name$entity->id()), E_USER_WARNING);
          }
        }
      }
      
Home | Imprint | This part of the site doesn't use cookies.