getMeta example



  /** * {@inheritdoc} */
  public function normalize($object$format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
    assert($object instanceof ResourceIdentifier);
    $normalization = [
      'type' => $object->getTypeName(),
      'id' => $object->getId(),
    ];
    if ($object->getMeta()) {
      $normalization['meta'] = $this->serializer->normalize($object->getMeta()$format$context);
    }
    return CacheableNormalization::permanent($normalization);
  }

  /** * {@inheritdoc} */
  public function denormalize($data$class$format = NULL, array $context = []): mixed {
    // If we get here, it's via a relationship POST/PATCH.     /** @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
    
// There are no relationships that need to be added so we can exit early.     if (empty($new_resource_identifiers)) {
      $status = static::relationshipResponseRequiresBody($resource_identifiers$original_resource_identifiers) ? 200 : 204;
      return $this->getRelationship($resource_type$entity$related$request$status);
    }

    $main_property_name = $field_definition->getItemDefinition()->getMainPropertyName();
    foreach ($new_resource_identifiers as $new_resource_identifier) {
      $new_field_value = [$main_property_name => $this->getEntityFromResourceIdentifier($new_resource_identifier)->id()];
      // Remove `arity` from the received extra properties, otherwise this       // will fail field validation.       $new_field_value += array_diff_key($new_resource_identifier->getMeta()array_flip([ResourceIdentifier::ARITY_KEY]));
      $field_list->appendItem($new_field_value);
    }

    $this->validate($entity);
    $entity->save();

    $final_resource_identifiers = ResourceIdentifier::toResourceIdentifiersWithArityRequired($field_list);
    $status = static::relationshipResponseRequiresBody($resource_identifiers$final_resource_identifiers) ? 200 : 204;
    return $this->getRelationship($resource_type$entity$related$request$status);
  }

  
if ($data instanceof ErrorCollection) {
      $document['errors'] = $this->normalizeErrorDocument($object$format$context);
    }
    else {
      // Add data.       $document['data'] = $this->serializer->normalize($data$format$context);
      // Add includes.       $document['included'] = $this->serializer->normalize($object->getIncludes()$format$context)->omitIfEmpty();
      // Add omissions and metadata.       $normalized_omissions = $this->normalizeOmissionsLinks($object->getOmissions()$format$context);
      $meta = !$normalized_omissions instanceof CacheableOmission
        ? array_merge($object->getMeta()['omitted' => $normalized_omissions->getNormalization()])
        : $object->getMeta();
      $document['meta'] = (new CacheableNormalization($normalized_omissions$meta))->omitIfEmpty();
    }
    // Add document links.     $document['links'] = $this->serializer->normalize($object->getLinks()$format$context)->omitIfEmpty();
    // Every JSON:API document contains absolute URLs.     return CacheableNormalization::aggregate($document)->withCacheableDependency((new CacheableMetadata())->addCacheContexts(['url.site']));
  }

  /** * Normalizes an error collection. * * @param \Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel $document * The document to normalize. * @param string $format * The normalization format. * @param array $context * The normalization context. * * @return \Drupal\jsonapi\Normalizer\Value\CacheableNormalization * The normalized document. * * @todo: refactor this to use CacheableNormalization::aggregate in https://www.drupal.org/project/drupal/issues/3036284. */

                $propertyType = $property->getType();
                if ($type === "MemberExpression" &&
                    ($node->getComputed() ||
                    ($propertyType !== "Identifier" && $propertyType !== "PrivateIdentifier"))) {
                    $code .= ($optional ? "?." : "") . "[" . $compiledProperty . "]";
                } else {
                    $code .= ($optional ? "?." : ".") . $compiledProperty;
                }
            break;
            case "MetaProperty":
                $code .= $node->getMeta() . "." . $node->getProperty();
            break;
            case "MethodDefinition":
                if ($node->getStatic()) {
                    $code .= "static ";
                }
                $value = $node->getValue();
                $key = $node->getKey();
                $kind = $node->getKind();
                if ($kind === $node::KIND_GET || $kind === $node::KIND_SET) {
                    $code .= $kind . " ";
                } else {
                    
class MetadataTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());

        $firstAction = $flowActions->getActions()->getActions()[0];
        $meta = $firstAction->getMeta();

        static::assertEquals('abc.cde.ccc', $meta->getName());
        static::assertEquals(['order', 'customer']$meta->getRequirements());
        static::assertEquals('https://example.xyz', $meta->getUrl());
        static::assertEquals('sw-pencil', $meta->getSwIcon());
        static::assertEquals('resource/pencil', $meta->getIcon());
        static::assertEquals(
            [
                'en-GB' => 'First action app',
                'de-DE' => 'First action app DE',
            ],
            
public function updateActions(Action $flowAction, string $appId, Context $context, string $defaultLocale): void
    {
        /** @var array<string, string> $existingFlowActions */
        $existingFlowActions = $this->connection->fetchAllKeyValue('SELECT name, LOWER(HEX(id)) FROM app_flow_action WHERE app_id = :appId', [
            'appId' => Uuid::fromHexToBytes($appId),
        ]);

        $flowActions = $flowAction->getActions() ? $flowAction->getActions()->getActions() : [];
        $upserts = [];

        foreach ($flowActions as $action) {
            if ($icon = $action->getMeta()->getIcon()) {
                $icon = $this->appLoader->loadFile($flowAction->getPath()$icon);
            }

            $payload = array_merge([
                'appId' => $appId,
                'iconRaw' => $icon,
            ]$action->toArray($defaultLocale));

            $existing = $existingFlowActions[$action->getMeta()->getName()] ?? null;
            if ($existing) {
                $payload['id'] = $existing;
                
    // See https://jsonapi.org/format/#fetching-relationships-responses-200 and     // https://jsonapi.org/format/#document-top-level.     return LinkCollection::merge($top_level_links$this->getLinks()->filter(function D$key) use ($top_level_links) {
      return !$top_level_links->hasLinkWithKey($key);
    })->withContext($top_level_links->getContext()));
  }

  /** * {@inheritdoc} */
  public function getMergedMeta(array $top_level_meta) {
    return NestedArray::mergeDeep($top_level_meta$this->getMeta());
  }

  /** * Builds a LinkCollection for the given entity reference field. * * @param \Drupal\jsonapi\JsonApiResource\ResourceObject $context * The context resource object of the relationship object. * @param \Drupal\Core\Field\EntityReferenceFieldItemListInterface $field * The entity reference field from which to create the links. * @param \Drupal\jsonapi\JsonApiResource\LinkCollection $links * Any extra links for the Relationship, if a `self` link is not provided, * one will be automatically added if the context resource is locatable and * is not internal. * * @return \Drupal\jsonapi\JsonApiResource\LinkCollection * The built links. */
'requirements' => ['order', 'customer'],
            'icon' => 'resource/pencil',
            'swIcon' => 'sw-pencil',
            'headline' => [
                'en-GB' => 'Headline for action',
                'de-DE' => 'Überschrift für Aktion',
            ],
            'delayable' => true,
            'badge' => 'abc',
        ];

        static::assertEquals($expected$this->action->getMeta()->toArray('en-GB'));
    }

    public function testGetHeaders(): void
    {
        static::assertArrayHasKey('parameters', $this->action->getHeaders()->toArray('eb-GB'));
    }

    public function testGetParameters(): void
    {
        static::assertArrayHasKey('parameters', $this->action->getParameters()->toArray('eb-GB'));
    }

    
class ActionTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());

        $firstAction = $flowActions->getActions()->getActions()[0];
        static::assertNotNull($firstAction->getMeta());
        static::assertNotNull($firstAction->getHeaders());
        static::assertNotNull($firstAction->getParameters());
        static::assertNotNull($firstAction->getConfig());

        static::assertEquals('abc.cde.ccc', $firstAction->getMeta()->getName());
        static::assertEquals(['order', 'customer']$firstAction->getMeta()->getRequirements());
        static::assertEquals(
            [
                'en-GB' => 'First action app',
                'de-DE' => 'First action app DE',
            ],
            

class RelationshipNormalizer extends NormalizerBase {

  /** * {@inheritdoc} */
  public function normalize($object$format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
    assert($object instanceof Relationship);
    return CacheableNormalization::aggregate([
      'data' => $this->serializer->normalize($object->getData()$format$context),
      'links' => $this->serializer->normalize($object->getLinks()$format$context)->omitIfEmpty(),
      'meta' => CacheableNormalization::permanent($object->getMeta())->omitIfEmpty(),
    ]);
  }

  /** * {@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;
  }

  

    private function getWebhooks(Manifest $manifest, ?Action $flowActions, string $appId, string $defaultLocale, bool $hasAppSecret): array
    {
        $actions = [];

        if ($flowActions) {
            $actions = $flowActions->getActions()?->getActions() ?? [];
        }

        $webhooks = array_map(function D$action) use ($appId) {
            $name = $action->getMeta()->getName();

            return [
                'name' => $name,
                'eventName' => $name,
                'url' => $action->getMeta()->getUrl(),
                'appId' => $appId,
                'active' => true,
                'errorCount' => 0,
            ];
        }$actions);

        
/** * Returns a copy of the given ResourceIdentifier with the given arity. * * @param int $arity * The new arity; must be a non-negative integer. * * @return static * A newly created ResourceIdentifier with the given arity, otherwise * the same. */
  public function withArity($arity) {
    return new static($this->getResourceType()$this->getId()[static::ARITY_KEY => $arity] + $this->getMeta());
  }

  /** * Gets the resource identifier objects metadata. * * @return array * The metadata. */
  public function getMeta() {
    return $this->meta;
  }

  
Home | Imprint | This part of the site doesn't use cookies.