getOperation example

$entityWriteResult = $this->versionManager->clone(
            $registry->getByEntityName('product'),
            Uuid::randomHex(),
            Uuid::randomHex(),
            Uuid::randomHex(),
            $writeContextMock,
            $this->createMock(CloneBehavior::class)
        );

        static::assertNotEmpty($entityWriteResult);
        static::assertSame('insert', $entityWriteResult['product'][0]->getOperation());
        static::assertSame('product', $entityWriteResult['product'][0]->getEntityName());
    }

    public function testCloneEntityNotExist(): void
    {
        $entityReaderMock = $this->createMock(EntityReaderInterface::class);
        $entityReaderMock->expects(static::once())->method('read')->willReturn(new EntityCollection([]));

        $this->versionManager = new VersionManager(
            $this->createMock(EntityWriterInterface::class),
            $entityReaderMock,
            

        return $this->errors;
    }

    public function getPrimaryKeys(string $entity): array
    {
        return $this->findPrimaryKeys($entity);
    }

    public function getDeletedPrimaryKeys(string $entity): array
    {
        return $this->findPrimaryKeys($entityfn (EntityWriteResult $result) => $result->getOperation() === EntityWriteResult::OPERATION_DELETE);
    }

    public function getPrimaryKeysWithPayload(string $entity): array
    {
        return $this->findPrimaryKeys($entityfunction DEntityWriteResult $result) {
            if ($result->getOperation() === EntityWriteResult::OPERATION_DELETE) {
                return true;
            }

            return !empty($result->getPayload());
        });
    }


    public function testItAddsMissingReadPermissionDependencies(): void
    {
        $permissionCollection = new PermissionCollection(self::PERMISSIONS);

        static::assertNotEmpty($permissionCollection->getElements());
        static::assertCount(7, $permissionCollection->getElements());

        $countReadPermissions = 0;
        foreach ($permissionCollection->getElements() as $permission) {
            if ($permission->getOperation() === AclRoleDefinition::PRIVILEGE_READ) {
                ++$countReadPermissions;
            }
        }

        static::assertEquals(4, $countReadPermissions);
    }

    public function testItFiltersDuplicatePermissions(): void
    {
        $permissionsData = [
            [
                
public function addDeleteResults(array $identifiers, array $notFound, array $parents): WriteResult
    {
        $results = $this->splitResultsByOperation($identifiers);

        $deleted = $this->addParentResults($results['deleted']$parents);

        $mapped = [];
        $updates = [];
        foreach ($deleted as $entity => $nested) {
            /** @var EntityWriteResult $result */
            foreach ($nested as $result) {
                if ($result->getOperation() === EntityWriteResult::OPERATION_UPDATE) {
                    $updates[$entity][] = $result;
                } else {
                    $mapped[$entity][] = $result;
                }
            }
        }

        $updates = array_merge_recursive($results['updated']$updates);

        return new WriteResult($mapped$notFoundarray_filter($updates));
    }

    
$this->cleanAllPackages();
  }

  /** * PRE_PACKAGE_INSTALL event handler. * * @param \Composer\Installer\PackageEvent $event * The package event. */
  public function onPrePackageInstall(PackageEvent $event) {
    /** @var \Composer\Package\CompletePackage $package */
    $package = $event->getOperation()->getPackage();
    $this->removeBinBeforeCleanup($package);
  }

  /** * PRE_PACKAGE_UPDATE event handler. * * @param \Composer\Installer\PackageEvent $event * The package event. */
  public function onPrePackageUpdate(PackageEvent $event) {
    /** @var \Composer\Package\CompletePackage $package */
    
$id = Uuid::randomBytes();

                $commands[] = new InsertCommand(
                    $this->versionCommitDataDefinition,
                    [
                        'id' => $id,
                        'version_commit_id' => $commitId,
                        'entity_name' => $entityName,
                        'entity_id' => Json::encode($primary),
                        'payload' => Json::encode($payload),
                        'user_id' => $userId,
                        'action' => $isClone ? 'clone' : $item->getOperation(),
                        'created_at' => $date,
                    ],
                    ['id' => $id],
                    EntityExistence::createForEntity(
                        $this->versionCommitDataDefinition->getEntityName(),
                        ['id' => Uuid::fromBytesToHex($id)],
                    ),
                    ''
                );
            }
        }

        
$payload = array_merge($payload$this->getMergeableTranslationPayload($translationResult));
        }

        if (empty($payload)) {
            return null;
        }

        return new EntityWriteResult(
            $writeResult->getPrimaryKey(),
            $payload,
            $writeResult->getEntityName(),
            $writeResult->getOperation(),
            $writeResult->getExistence(),
            $writeResult->getChangeSet()
        );
    }

    /** * @param EntityWriteResult[] $writeResults * @param string|array<string, string> $entityKey * * @return EntityWriteResult[] */
    
unset($allowed_packages[$root_package->getName()]);
      $allowed_packages[$root_package->getName()] = $root_package;
    }
    // Handle any newly-added packages that are not already allowed.     return $this->evaluateNewPackages($allowed_packages);
  }

  /** * {@inheritdoc} */
  public function event(PackageEvent $event) {
    $operation = $event->getOperation();
    // Determine the package. Later, in evaluateNewPackages(), we will report     // which of the newly-installed packages have scaffold operations, and     // whether or not they are allowed to scaffold by the allowed-packages     // option in the root-level composer.json file.     $package = $operation->getOperationType() === 'update' ? $operation->getTargetPackage() : $operation->getPackage();
    if (ScaffoldOptions::hasOptions($package->getExtra())) {
      $this->newPackages[$package->getName()] = $package;
    }
  }

  /** * Gets all packages that are allowed in the top-level composer.json. * * We will implicitly allow the projects 'drupal/legacy-scaffold-assets' * and 'drupal/core' to scaffold files, if they are present. Any other * project must be explicitly whitelisted in the top-level composer.json * file in order to be allowed to override scaffold files. * * @return array * An array of allowed Composer package names. */
public static function getSubscribedEvents(): array
    {
        return [
            CustomerEvents::CUSTOMER_WRITTEN_EVENT => 'onCustomerWritten',
            CustomerEvents::CUSTOMER_DELETED_EVENT => 'onCustomerDeleted',
        ];
    }

    public function onCustomerWritten(EntityWrittenEvent $event): void
    {
        foreach ($event->getWriteResults() as $writeResult) {
            if ($writeResult->getOperation() !== EntityWriteResult::OPERATION_UPDATE) {
                continue;
            }

            $payload = $writeResult->getPayload();
            if (!$this->customerCredentialsChanged($payload)) {
                continue;
            }

            $customerId = $payload['id'];
            $newToken = $this->invalidateUsingSession($customerId);

            
/** * @return array{entity: string, operation: string, primaryKey: array<string, string>|string, updatedFields?: array<string>}[] */
    public function getPayloadFromEvent(EntityWrittenEvent $event): array
    {
        $payload = [];

        foreach ($event->getWriteResults() as $writeResult) {
            $result = [
                'entity' => $writeResult->getEntityName(),
                'operation' => $writeResult->getOperation(),
                'primaryKey' => $writeResult->getPrimaryKey(),
            ];

            if (!$event instanceof EntityDeletedEvent) {
                $result['updatedFields'] = array_keys($writeResult->getPayload());
            }

            $payload[] = $result;
        }

        return $payload;
    }

  protected function init(FormStateInterface $form_state) {
    // Ensure we act on the translation object corresponding to the current form     // language.     $this->initFormLangcodes($form_state);
    $langcode = $this->getFormLangcode($form_state);
    $this->entity = $this->entity->hasTranslation($langcode) ? $this->entity->getTranslation($langcode) : $this->entity->addTranslation($langcode);

    $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation());
    $this->setFormDisplay($form_display$form_state);

    parent::init($form_state);
  }

  /** * Initializes form language code values. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */
  

  public function getBaseFormId() {
    return $this->getEntity()->getEntityTypeId() . '_layout_builder_form';
  }

  /** * {@inheritdoc} */
  protected function init(FormStateInterface $form_state) {
    parent::init($form_state);

    $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation(), FALSE);
    $form_display->setComponent(OverridesSectionStorage::FIELD_NAME, [
      'type' => 'layout_builder_widget',
      'weight' => -10,
      'settings' => [],
    ]);

    $this->setFormDisplay($form_display$form_state);
  }

  /** * {@inheritdoc} */
$entity = $form_object->getEntity();

      $this->entityTypeManager
        ->getHandler($entity->getEntityTypeId(), 'moderation')
        ->enforceRevisionsEntityFormAlter($form$form_state$form_id);

      // Submit handler to redirect to the latest version, if available.       $form['actions']['submit']['#submit'][] = [EntityTypeInfo::class, 'bundleFormRedirect'];

      // Move the 'moderation_state' field widget to the footer region, if       // available.       if (isset($form['footer']) && in_array($form_object->getOperation()['edit', 'default'], TRUE)) {
        $form['moderation_state']['#group'] = 'footer';
      }

      // If the publishing status exists in the meta region, replace it with       // the current state instead.       if (isset($form['meta']['published'])) {
        $form['meta']['published']['#markup'] = $this->moderationInfo->getWorkflowForEntity($entity)->getTypePlugin()->getState($entity->moderation_state->value)->label();
      }
    }
  }

  
// we don't want to trigger to `update` method when we are inside the order process         if ($event->getContext()->hasState('checkout-order-route')) {
            return;
        }

        foreach ($event->getWriteResults() as $result) {
            if ($result->hasPayload('referencedId') && $result->getProperty('type') === LineItem::PRODUCT_LINE_ITEM_TYPE) {
                $ids[] = $result->getProperty('referencedId');
            }

            if ($result->getOperation() === EntityWriteResult::OPERATION_INSERT) {
                continue;
            }

            $changeSet = $result->getChangeSet();
            if (!$changeSet) {
                continue;
            }

            $type = $changeSet->getBefore('type');

            if ($type !== LineItem::PRODUCT_LINE_ITEM_TYPE) {
                
public function __construct(private readonly array $writeResults)
    {
    }

    /** * `only()` filters the writeResults by the given operation names and returns a new collection. * * @param string ...$operations The operations which should be filters, one of `insert`, `update` od `delete`. */
    public function only(string ...$operations): self
    {
        $writeResults = array_filter($this->writeResults, fn (EntityWriteResult $result): bool => \in_array($result->getOperation()$operations, true));

        return new self($writeResults);
    }

    /** * `with()` filters the writeResults by changes to the given properties and returns a new collection. * At least one of the given properties need to be in the change-set. * * @param string ...$properties The properties that should be in the change-set of the writeResult. */
    public function with(string ...$properties): self
    {
Home | Imprint | This part of the site doesn't use cookies.