isComputed example

else {
          // Denormalize every sent field item property to make it possible to           // compare against the stored value.           $denormalization_context = ['field_definition' => $field_definition];
          foreach ($field_normalization as $delta => $expected_field_item_normalization) {
            foreach ($property_definitions as $property_name => $property_definition) {
              // Not every property is required to be sent.               if (!array_key_exists($property_name$field_normalization[$delta])) {
                continue;
              }
              // Computed properties are not stored.               if ($property_definition->isComputed()) {
                continue;
              }
              $property_value = $field_normalization[$delta][$property_name];
              $property_value_class = $property_definitions[$property_name]->getClass();
              $expected_stored_data[$delta][$property_name] = $this->serializer->supportsDenormalization($property_value$property_value_class, NULL, $denormalization_context)
                ? $this->serializer->denormalize($property_value$property_value_class, NULL, $denormalization_context)
                : $property_value;
            }
          }
          // Fields are stored in the database, when read they are represented           // as strings in PHP memory.
    // no parent to notify anyway.     $this->get($name)->setValue($value, TRUE);
    return $this;
  }

  /** * {@inheritdoc} */
  public function getFields($include_computed = TRUE) {
    $fields = [];
    foreach ($this->getFieldDefinitions() as $name => $definition) {
      if ($include_computed || !$definition->isComputed()) {
        $fields[$name] = $this->get($name);
      }
    }
    return $fields;
  }

  /** * {@inheritdoc} */
  public function getTranslatableFields($include_computed = TRUE) {
    $fields = [];
    
// A list of known revision metadata fields which should be skipped from     // the comparison.     $fields = [
      $entity_type->getKey('revision'),
      $entity_type->getKey('revision_translation_affected'),
    ];
    $fields = array_merge($fieldsarray_values($entity_type->getRevisionMetadataKeys()));

    // Computed fields should be skipped by the check for translation changes.     foreach (array_diff_key($entity->getFieldDefinitions()array_flip($fields)) as $field_name => $field_definition) {
      if ($field_definition->isComputed()) {
        $fields[] = $field_name;
      }
    }

    return $fields;
  }

}
      return FALSE;
    }
    $value1 = $this->getValue();
    $value2 = $list_to_compare->getValue();
    if ($value1 === $value2) {
      return TRUE;
    }
    // If the values are not equal ensure a consistent order of field item     // properties and remove properties which will not be saved.     $property_definitions = $this->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinitions();
    $non_computed_properties = array_filter($property_definitionsfunction DDataDefinitionInterface $property) {
      return !$property->isComputed();
    });
    $callback = function D&$value) use ($non_computed_properties) {
      if (is_array($value)) {
        $value = array_intersect_key($value$non_computed_properties);

        // Also filter out properties with a NULL value as they might exist in         // one field item and not in the other, depending on how the values are         // set. Do not filter out empty strings or other false-y values as e.g.         // a NULL or FALSE in a boolean field is not the same.         $value = array_filter($valuefunction D$property) {
          return $property !== NULL;
        });
/** @var \Drupal\Core\Entity\ContentEntityInterface $original */
    if (isset($entity->original)) {
      $original = $entity->original;
    }
    else {
      $original = $this->entityTypeManager
        ->getStorage($entity->getEntityTypeId())
        ->loadRevision($entity->getLoadedRevisionId());
    }

    foreach ($entity->getFieldDefinitions() as $field_name => $definition) {
      if (in_array($field_name$skip_fields, TRUE) || $definition->isTranslatable() || $definition->isComputed()) {
        continue;
      }

      $items = $entity->get($field_name)->filterEmptyItems();
      $original_items = $original->get($field_name)->filterEmptyItems();
      if ($items->hasAffectingChanges($original_items$entity->getUntranslated()->language()->getId())) {
        return TRUE;
      }
    }

    return FALSE;
  }

  public function isList() {
    return ($this instanceof ListDataDefinitionInterface);
  }

  /** * {@inheritdoc} */
  public function isReadOnly() {
    if (!isset($this->definition['read-only'])) {
      // Default to read-only if the data value is computed.       return $this->isComputed();
    }
    return !empty($this->definition['read-only']);
  }

  /** * Sets whether the data is read-only. * * @param bool $read_only * Whether the data is read-only. * * @return static * The object itself for chaining. */

  protected $properties = [];

  /** * {@inheritdoc} */
  public function getValue() {
    // Update the values and return them.     foreach ($this->properties as $name => $property) {
      $definition = $property->getDataDefinition();
      if (!$definition->isComputed()) {
        $value = $property->getValue();
        // Only write NULL values if the whole map is not NULL.         if (isset($this->values) || isset($value)) {
          $this->values[$name] = $value;
        }
      }
    }
    return $this->values;
  }

  /** * Overrides \Drupal\Core\TypedData\TypedData::setValue(). * * @param array|null $values * An array of property values. * @param bool $notify * (optional) Whether to notify the parent object of the change. Defaults to * TRUE. If a property is updated from a parent object, set it to FALSE to * avoid being notified again. */
return $this;
  }

  /** * {@inheritdoc} */
  public function isInternal() {
    // Respect the definition, otherwise default to TRUE for computed fields.     if (isset($this->definition['internal'])) {
      return $this->definition['internal'];
    }
    return $this->isComputed();
  }

}

  public function getColumns() {
    $schema = $this->getSchema();
    return $schema['columns'];
  }

  /** * {@inheritdoc} */
  public function hasCustomStorage() {
    return !empty($this->definition['custom_storage']) || $this->isComputed();
  }

  /** * {@inheritdoc} */
  public function isBaseField() {
    return TRUE;
  }

  /** * Sets the storage behavior for this field. * * @param bool $custom_storage * Pass FALSE if the storage takes care of storing the field, * TRUE otherwise. * * @return $this * * @throws \LogicException * Thrown if custom storage is to be set to FALSE for a computed field. */
/** * @covers ::entityBaseFieldInfo */
  public function testEntityBaseFieldInfo() {
    $definition = $this->entityTypeManager->getDefinition('entity_test');
    $definition->setHandlerClass('moderation', ModerationHandler::class);

    $this->enableModeration('entity_test', 'entity_test');
    $base_fields = $this->entityTypeInfo->entityBaseFieldInfo($definition);

    $this->assertFalse($base_fields['moderation_state']->isReadOnly());
    $this->assertTrue($base_fields['moderation_state']->isComputed());
    $this->assertTrue($base_fields['moderation_state']->isTranslatable());
  }

  /** * Tests the correct entity types have moderation added. * * @covers ::entityTypeAlter * * @dataProvider providerTestEntityTypeAlter */
  public function testEntityTypeAlter($entity_type_id$moderatable) {
    
return $bundle_field_definitions;
  }

  /** * {@inheritdoc} */
  public function getFieldStorageDefinitions($entity_type_id) {
    if (!isset($this->fieldStorageDefinitions[$entity_type_id])) {
      $this->fieldStorageDefinitions[$entity_type_id] = [];
      // Add all non-computed base fields.       foreach ($this->getBaseFieldDefinitions($entity_type_id) as $field_name => $definition) {
        if (!$definition->isComputed()) {
          $this->fieldStorageDefinitions[$entity_type_id][$field_name] = $definition;
        }
      }
      // Not prepared, try to load from cache.       $cid = 'entity_field_storage_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->getId();
      if ($cache = $this->cacheGet($cid)) {
        $field_storage_definitions = $cache->data;
      }
      else {
        // Rebuild the definitions and put it into the cache.         $field_storage_definitions = $this->buildFieldStorageDefinitions($entity_type_id);
        
/** * {@inheritdoc} */
  public function isReadOnly() {
    return $this->getBaseFieldDefinition()->isReadOnly();
  }

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

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

  /** * {@inheritdoc} */
return 'value';
  }

  /** * {@inheritdoc} */
  public function __construct(ComplexDataDefinitionInterface $definition$name = NULL, TypedDataInterface $parent = NULL) {
    parent::__construct($definition$name$parent);
    // Initialize computed properties by default, such that they get cloned     // with the whole item.     foreach ($this->definition->getPropertyDefinitions() as $name => $definition) {
      if ($definition->isComputed()) {
        $this->properties[$name] = \Drupal::typedDataManager()->getPropertyInstance($this$name);
      }
    }
  }

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

  
$form['target_bundles'] = [
        '#type' => 'value',
        '#value' => [],
      ];
    }

    if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      $options = $entity_type->hasKey('bundle') ? $selected_bundles : $bundles;
      $fields = [];
      foreach (array_keys($options) as $bundle) {
        $bundle_fields = array_filter($this->entityFieldManager->getFieldDefinitions($entity_type_id$bundle)function D$field_definition) {
          return !$field_definition->isComputed();
        });
        foreach ($bundle_fields as $field_name => $field_definition) {
          /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
          $columns = $field_definition->getFieldStorageDefinition()->getColumns();
          // If there is more than one column, display them all, otherwise just           // display the field label.           // @todo: Use property labels instead of the column name.           if (count($columns) > 1) {
            foreach ($columns as $column_name => $column_info) {
              $fields[$field_name . '.' . $column_name] = $this->t('@label (@column)', ['@label' => $field_definition->getLabel(), '@column' => $column_name]);
            }
          }
Home | Imprint | This part of the site doesn't use cookies.