mapFromStorageRecords example

protected function mapFromStorageRecords(array $records) {
    foreach ($records as $id => &$record) {
      try {
        $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
      }
      catch (PluginNotFoundException $e) {
        $config_id = $this->getPrefix() . $id;
        throw new PluginNotFoundException($record['field_type'], "Unable to determine class for field type '{$record['field_type']}' found in the '$config_id' configuration", $e->getCode()$e);
      }
      $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
    }
    return parent::mapFromStorageRecords($records);
  }

  /** * {@inheritdoc} */
  protected function mapToStorageRecord(EntityInterface $entity) {
    $record = parent::mapToStorageRecord($entity);
    $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
    $record['settings'] = $class::fieldSettingsToConfigData($record['settings']);
    return $record;
  }

}
protected function mapFromStorageRecords(array $records) {
    foreach ($records as $id => &$record) {
      try {
        $class = $this->fieldTypeManager->getPluginClass($record['type']);
      }
      catch (PluginNotFoundException $e) {
        $config_id = $this->getPrefix() . $id;
        throw new PluginNotFoundException($record['type'], "Unable to determine class for field type '{$record['type']}' found in the '$config_id' configuration", $e->getCode()$e);
      }
      $record['settings'] = $class::storageSettingsFromConfigData($record['settings']);
    }
    return parent::mapFromStorageRecords($records);
  }

  /** * {@inheritdoc} */
  protected function mapToStorageRecord(EntityInterface $entity) {
    $record = parent::mapToStorageRecord($entity);
    $class = $this->fieldTypeManager->getPluginClass($record['type']);
    $record['settings'] = $class::storageSettingsToConfigData($record['settings']);
    return $record;
  }

}
/** * {@inheritdoc} */
  protected function mapFromStorageRecords(array $records) {
    foreach ($records as &$record) {
      if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
        $sections = &$record['third_party_settings']['layout_builder']['sections'];
        $sections = array_map([Section::class, 'fromArray']$sections);
      }
    }
    return parent::mapFromStorageRecords($records);
  }

}


    // Load all of the configuration entities.     /** @var \Drupal\Core\Config\Config[] $configs */
    $configs = [];
    $records = [];
    foreach ($this->configFactory->loadMultiple($names) as $config) {
      $id = $config->get($this->idKey);
      $records[$id] = $this->overrideFree ? $config->getOriginal(NULL, FALSE) : $config->get();
      $configs[$id] = $config;
    }
    $entities = $this->mapFromStorageRecords($records);

    // Config entities wrap config objects, and therefore they need to inherit     // the cacheability metadata of config objects (to ensure e.g. additional     // cacheability metadata added by config overrides is not lost).     foreach ($entities as $id => $entity) {
      // But rather than simply inheriting all cacheability metadata of config       // objects, we need to make sure the self-referring cache tag that is       // present on Config objects is not added to the Config entity. It must be       // removed for 3 reasons:       // 1. When renaming/duplicating a Config entity, the cache tag of the       // original config object would remain present, which would be wrong.
/** * {@inheritdoc} */
  public function doLoadMultiple(array $ids = NULL) {
    if (empty($ids)) {
      $entities = $this->keyValueStore->getAll();
    }
    else {
      $entities = $this->keyValueStore->getMultiple($ids);
    }
    return $this->mapFromStorageRecords($entities);
  }

  /** * {@inheritdoc} */
  public function loadRevision($revision_id) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Entity\RevisionableStorageInterface::loadRevision instead. See https://www.drupal.org/node/3294237', E_USER_DEPRECATED);

    return NULL;
  }

  
      // it is empty as this would load all entities.       $ids = $this->cleanIds($ids);
    }

    if ($ids === NULL || $ids) {
      // Build and execute the query.       $query_result = $this->buildQuery($ids)->execute();
      $records = $query_result->fetchAllAssoc($this->idKey);

      // Map the loaded records into entity objects and according fields.       if ($records) {
        $entities = $this->mapFromStorageRecords($records);
      }
    }

    return $entities;
  }

  /** * Maps from storage records to entity objects, and attaches fields. * * @param array $records * Associative array of query results, keyed on the entity ID or revision * ID. * @param bool $load_from_revision * (optional) Flag to indicate whether revisions should be loaded or not. * Defaults to FALSE. * * @return array * An array of entity objects implementing the EntityInterface. */
Home | Imprint | This part of the site doesn't use cookies.