getCastedValue example

if (in_array($object->getName()$serialized_property_names, TRUE)) {
        return unserialize($object->getValue());
      }
    }

    // Typed data casts NULL objects to their empty variants, so for example     // the empty string ('') for string type data, or 0 for integer typed data.     // In a better world with typed data implementing algebraic data types,     // getCastedValue would return NULL, but as typed data is not aware of real     // optional values on the primitive level, we implement our own optional     // value normalization here.     return $object->getValue() === NULL ? NULL : $object->getCastedValue();
  }

  /** * {@inheritdoc} */
  public function hasCacheableSupportsMethod(): bool {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use getSupportedTypes() instead. See https://www.drupal.org/node/3359695', E_USER_DEPRECATED);

    return TRUE;
  }

  

          ],
        ],
      ];
    };
    $resource_type = reset($relatable_resource_types);
    // A non-empty entity reference field that refers to a non-existent entity     // is not a data integrity problem. For example, Term entities' "parent"     // entity reference field uses target_id zero to refer to the non-existent     // "<root>" term. And references to entities that no longer exist are not     // cleaned up by Drupal; hence we map it to a "missing" resource.     if ($field->getFieldDefinition()->getSetting('target_type') === 'taxonomy_term' && $item->get('target_id')->getCastedValue() === 0) {
      if (count($relatable_resource_types) !== 1) {
        throw new \RuntimeException('Relationships to virtual resources are possible only if a single resource type is relatable.');
      }
      return new static($resource_type, 'virtual', $get_metadata('virtual'));
    }
    else {
      // In case of a dangling reference, it is impossible to determine which       // resource type it used to reference, because that requires knowing the       // referenced bundle, which Drupal does not store.       // If we can reliably determine the resource type of the dangling       // reference, use it; otherwise conjure a fake resource type out of thin
    // empty choices for undefined values; for instance, if a term reference     // field points to an empty vocabulary.     if (!isset($value)) {
      return;
    }

    // Get the value with the proper datatype in order to make strict     // comparisons using in_array().     if (!($typed_data instanceof PrimitiveInterface)) {
      throw new \LogicException('The data type must be a PrimitiveInterface at this point.');
    }
    $value = $typed_data->getCastedValue();

    // In a better world where typed data just returns typed values, we could     // set a constraint callback to use the OptionsProviderInterface.     // This is not possible right now though because we do the typecasting     // further down.     if ($constraint->callback) {
      if (!\is_callable($choices = [$this->context->getObject()$constraint->callback])
        && !\is_callable($choices = [$this->context->getClassName()$constraint->callback])
        && !\is_callable($choices = $constraint->callback)
      ) {
        throw new ConstraintDefinitionException('The AllowedValuesConstraint constraint expects a valid callback');
      }
// Special handling for integers and floats since the configuration         // system is primarily concerned with saving values from the Form API         // we have to special case the meaning of an empty string for numeric         // types. In PHP this would be casted to a 0 but for the purposes of         // configuration we need to treat this as a NULL.         $empty_value = $value === '' && ($element instanceof IntegerInterface || $element instanceof FloatInterface);

        if ($value === NULL || $empty_value) {
          $value = NULL;
        }
        else {
          $value = $element->getCastedValue();
        }
      }
    }
    else {
      // Throw exception on any non-scalar or non-array value.       if (!is_array($value)) {
        throw new UnsupportedDataTypeConfigException("Invalid data type for config element {$this->getName()}:$key");
      }
      // Recurse into any nested keys.       foreach ($value as $nested_value_key => $nested_value) {
        $lookup_key = $key ? $key . '.' . $nested_value_key : $nested_value_key;
        
Home | Imprint | This part of the site doesn't use cookies.