hasTrustedData example

public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    if (!isset($this->weight) && ($roles = $storage->loadMultiple())) {
      // Set a role weight to make this new role last.       $max = array_reduce($rolesfunction D$max$role) {
        return $max > $role->weight ? $max : $role->weight;
      });
      $this->weight = $max + 1;
    }

    if (!$this->isSyncing() && $this->hasTrustedData()) {
      // Permissions are always ordered alphabetically to avoid conflicts in the       // exported configuration. If the save is not trusted then the       // configuration will be sorted by StorableConfigBase.       sort($this->permissions);
    }
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    
parent::preSave($storage);

    $displays = $this->get('display');

    // Sort the displays.     ksort($displays);
    $this->set('display', ['default' => $displays['default']] + $displays);

    // Calculating the cacheability metadata is only needed when the view is     // saved through the UI or API. It should not be done when we are syncing     // configuration or installing modules.     if (!$this->isSyncing() && !$this->hasTrustedData()) {
      $this->addCacheMetadata();
    }
  }

  /** * Fills in the cache metadata of this view. * * Cache metadata is set per view and per display, and ends up being stored in * the view's configuration. This allows Views to determine very efficiently: * - the max-age * - the cache contexts * - the cache tags * * In other words: this allows us to do the (expensive) work of initializing * Views plugins and handlers to determine their effect on the cacheability of * a view at save time rather than at runtime. */
if ($id !== $entity->id()) {
      // Renaming a config object needs to cater for:       // - Storage needs to access the original object.       // - The object needs to be renamed/copied in ConfigFactory and reloaded.       // - All instances of the object need to be renamed.       $this->configFactory->rename($prefix . $id$config_name);
    }
    $config = $this->configFactory->getEditable($config_name);

    // Retrieve the desired properties and set them in config.     $config->setData($this->mapToStorageRecord($entity));
    $config->save($entity->hasTrustedData());

    // Update the entity with the values stored in configuration. It is possible     // that configuration schema has casted some of the values.     if (!$entity->hasTrustedData()) {
      $data = $this->mapFromStorageRecords([$config->get()]);
      $updated_entity = current($data);

      foreach (array_keys($config->get()) as $property) {
        $value = $updated_entity->get($property);
        $entity->set($property$value);
      }
    }
/** * {@inheritdoc} */
  public function trustData() {
    return $this->storage->trustData();
  }

  /** * {@inheritdoc} */
  public function hasTrustedData() {
    return $this->storage->hasTrustedData();
  }

  /** * {@inheritdoc} */
  public function addCacheableDependency($other_object) {
    $this->storage->addCacheableDependency($other_object);
    return $this;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.