getKeys example

'length' => 32,
            'not null' => FALSE,
          ],
        ],
      ],
    ];
    $actual = $this->installedStorageSchema->get('entity_test.field_schema_data.shape');
    $this->assertSame($expected$actual);

    // Make the field an entity key, so that it will get marked as NOT NULL.     $entity_type = $this->entityDefinitionUpdateManager->getEntityType('entity_test');
    $original_keys = $entity_type->getKeys();
    $entity_type->set('entity_keys', $original_keys + ['shape' => 'shape']);
    $this->entityDefinitionUpdateManager->updateEntityType($entity_type);

    // Update the field and make sure the schema got updated.     $this->entityDefinitionUpdateManager->updateFieldStorageDefinition($field);
    $expected['entity_test']['fields']['shape__shape']['not null'] = TRUE;
    $expected['entity_test']['fields']['shape__color']['not null'] = TRUE;
    $actual = $this->installedStorageSchema->get('entity_test.field_schema_data.shape');
    $this->assertSame($expected$actual);

    // Remove the entity key again and check that the schema got reverted.
private readonly array $states
    ) {
    }

    public function __destruct()
    {
        $this->gateway->flush();
    }

    public function __invoke(InvalidateCacheEvent $event): void
    {
        $this->gateway->invalidate($event->getKeys());
    }

    public function lookup(Request $request): ?Response
    {
        return null;
    }

    public function write(Request $request, Response $response): string
    {
        $tags = $this->tracer->get('all');

        

  protected function modifyBaseField() {
    $this->addBaseField('text');
  }

  /** * Promotes a field to an entity key. */
  protected function makeBaseFieldEntityKey() {
    $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_update');
    $entity_keys = $entity_type->getKeys();
    $entity_keys['new_base_field'] = 'new_base_field';
    $entity_type->set('entity_keys', $entity_keys);
    $this->state->set('entity_test_update.entity_type', $entity_type);
  }

  /** * Removes the new base field from the 'entity_test_update' entity type. * * @param string $entity_type_id * (optional) The entity type ID the base field should be attached to. */
  


                    $extensions[$propertyName] = ['type' => $type, 'entity' => $entity];
                }

                $properties['extensions']['properties'] = $extensions;
            }

            $entityName = $definition->getEntityName();
            $schemaDefinitions[$entityName] = [
                'name' => $entityName,
                'translatable' => $definition->getFields()->filterInstance(TranslatedField::class)->getKeys(),
                'properties' => $properties,
            ];
        }

        return $schemaDefinitions;
    }

    private function getResourceUri(EntityDefinition $definition, string $rootPath = '/'): string
    {
        return ltrim('/', $rootPath) . '/' . str_replace('_', '-', $definition->getEntityName());
    }

    
$criteria = new Criteria();
        $criteria->addAggregation(new TermsAggregation('distinct_author', 'author'));

        /** @var TermsResult|null $aggregation */
        $aggregation = $this->snippetRepository->aggregate($criteria$context)
                ->get('distinct_author');

        if (!$aggregation || empty($aggregation->getBuckets())) {
            $result = [];
        } else {
            $result = $aggregation->getKeys();
        }

        $authors = array_flip($result);
        foreach ($files as $file) {
            $authors[$file['author']] = true;
        }
        $result = array_keys($authors);
        sort($result);

        return $result;
    }

    

    private function getInstalledThemeNames(Context $context): array
    {
        if ($this->installedThemeNames === null && $this->themeRepository instanceof EntityRepository) {
            $themeNameAggregationName = 'theme_names';
            $criteria = new Criteria();
            $criteria->addAggregation(new TermsAggregation($themeNameAggregationName, 'technicalName'));

            /** @var TermsResult $themeNameAggregation */
            $themeNameAggregation = $this->themeRepository->aggregate($criteria$context)->get($themeNameAggregationName);

            return $this->installedThemeNames = $themeNameAggregation->getKeys();
        }

        return $this->installedThemeNames ?? [];
    }

    private function loadLocalAppsCollection(Context $context): ExtensionCollection
    {
        $apps = $this->appLoader->load();
        $collection = new ExtensionCollection();
        $language = $this->localeProvider->getLocaleFromContext($context);

        
foreach ($values as $key => $value) {
      // If the key matches an existing property set the value to the property       // to set properties like isDefaultRevision.       // @todo: Should this be converted somehow?       if (property_exists($this$key) && isset($value[LanguageInterface::LANGCODE_DEFAULT])) {
        $this->$key = $value[LanguageInterface::LANGCODE_DEFAULT];
      }
    }

    $this->values = $values;
    foreach ($this->getEntityType()->getKeys() as $key => $field_name) {
      if (isset($this->values[$field_name])) {
        if (is_array($this->values[$field_name])) {
          // We store untranslatable fields into an entity key without using a           // langcode key.           if (!$this->getFieldDefinition($field_name)->isTranslatable()) {
            if (isset($this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT])) {
              if (is_array($this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT])) {
                if (isset($this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT][0]['value'])) {
                  $this->entityKeys[$key] = $this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT][0]['value'];
                }
              }
              

  protected function buildBaseFieldDefinitions($entity_type_id) {
    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    $class = $entity_type->getClass();
    /** @var string[] $keys */
    $keys = array_filter($entity_type->getKeys());

    // Fail with an exception for non-fieldable entity types.     if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      throw new \LogicException("Getting the base fields is not supported for entity type {$entity_type->getLabel()}.");
    }

    // Retrieve base field definitions.     /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $base_field_definitions */
    $base_field_definitions = $class::baseFieldDefinitions($entity_type);

    // Make sure translatable entity types are correctly defined.
    // context.     $this->drupalCreateContentType(['type' => 'page']);
    $node = $this->createNode();

    // Get a fully built entity view render array.     $build = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node, 'full');

    // Render it so the default cache contexts are applied.     $renderer->renderRoot($build);
    $this->assertContains('workspace', $build['#cache']['contexts']);

    $cid_parts = array_merge($build['#cache']['keys']$cache_contexts_manager->convertTokensToKeys($build['#cache']['contexts'])->getKeys());
    $this->assertContains('[workspace]=live', $cid_parts);

    // Test that a cache entry is created.     $cid = implode(':', $cid_parts);
    $bin = $build['#cache']['bin'];
    $this->assertInstanceOf(\stdClass::class$this->container->get('cache.' . $bin)->get($cid));

    // Switch to the 'stage' workspace and check that the correct workspace     // cache context is used.     $test_user = $this->drupalCreateUser(['view any workspace']);
    $this->drupalLogin($test_user);

    
$key_data = [
        'build_info' => $build_info,
      ];
      // @todo https://www.drupal.org/node/2433591 might solve it to not require       // the pager information here.       $key_data['pager'] = [
        'page' => $this->view->getCurrentPage(),
        'items_per_page' => $this->view->getItemsPerPage(),
        'offset' => $this->view->getOffset(),
      ];
      $key_data += \Drupal::service('cache_contexts_manager')->convertTokensToKeys($this->displayHandler->getCacheMetadata()->getCacheContexts())->getKeys();

      $this->resultsKey = $this->view->storage->id() . ':' . $this->displayHandler->display['id'] . ':results:' . hash('sha256', serialize($key_data));
    }

    return $this->resultsKey;
  }

  /** * Gets an array of cache tags for the current view. * * @return string[] * An array of cache tags based on the current view. */
'#element' => 4,
      ],
    ];

    return $build;
  }

  /** * #pre_render callback for #type => pager that shows the pager cache context. */
  public static function showPagerCacheContext(array $pager) {
    \Drupal::messenger()->addStatus(\Drupal::service('cache_contexts_manager')->convertTokensToKeys(['url.query_args.pagers:' . $pager['#element']])->getKeys()[0]);
    return $pager;
  }

  /** * {@inheritdoc} */
  public static function trustedCallbacks() {
    return ['showPagerCacheContext'];
  }

}
$entity->save();

    $this->assertEquals('published', $storage->load($entity->id())->moderation_state->value);
  }

  /** * Tests moderation of a non-translatable entity type with no langcode. */
  public function testNonLangcodeEntityTypeModeration() {
    // Unset the langcode entity key for 'entity_test_rev'.     $entity_type = clone $this->entityTypeManager->getDefinition($this->revEntityTypeId);
    $keys = $entity_type->getKeys();
    unset($keys['langcode']);
    $entity_type->set('entity_keys', $keys);
    \Drupal::state()->set($this->revEntityTypeId . '.entity_type', $entity_type);

    // Update the entity type in order to remove the 'langcode' field.     \Drupal::entityDefinitionUpdateManager()->updateFieldableEntityType($entity_type, \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type->id()));

    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow$this->revEntityTypeId, $this->revEntityTypeId);

    // Check that the tested entity type is not translatable and does not have a
    // EntityTypeManagerTestEntity class     $storage->getEntityClass(NULL)->willReturn(EntityTypeManagerTestEntity::class);
    $storage->getEntityClass(Argument::type('string'))->willReturn(EntityTypeManagerTestEntity::class);
    // When using the "test_entity_bundle_class" bundle, return the     // EntityTypeManagerTestEntityBundle class     $storage->getEntityClass('test_entity_bundle_class')->willReturn(EntityTypeManagerTestEntityBundle::class);

    $this->entityTypeManager->getStorage('test_entity_type')->willReturn($storage->reveal());
    $this->entityTypeManager->getStorage('base_field_override')->willReturn($storage->reveal());

    $this->entityType->getClass()->willReturn($entity_class);
    $this->entityType->getKeys()->willReturn($entity_keys + ['default_langcode' => 'default_langcode']);
    $this->entityType->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $this->entityType->isTranslatable()->willReturn(FALSE);
    $this->entityType->isRevisionable()->willReturn(FALSE);
    $this->entityType->getProvider()->willReturn('the_provider');
    $this->entityType->id()->willReturn('the_entity_id');

    return $field_definition->reveal();
  }

  /** * Tests the clearCachedFieldDefinitions() method. * * @covers ::clearCachedFieldDefinitions */
/** * @dataProvider casesSearchBaseOnConfigField */
    public function testInsertIntoSearchKeywordForEn(bool $searchable, bool $tokenize, int $ranking): void
    {
        $this->updateProductSearchConfigField($this->enSearchConfigId, $searchable$tokenize$ranking);

        $product = $this->getProduct();
        $configFields = $this->getConfigFieldsByLanguageId($this->enSearchConfigId);
        $analyzer = $this->getContainer()->get(ProductSearchKeywordAnalyzer::class);
        $analyzer = $analyzer->analyze($product$this->context, $configFields);
        $analyzerResult = $analyzer->getKeys();
        sort($analyzerResult);

        $expected = [];
        if ($searchable && $tokenize) {
            $expected = [
                'test',
                'product',
                'category',
                'manufacturer',
                123456123123123,
                'metadescription',
                
$collection = new TestCollection();
        static::assertEquals(0, $collection->count());

        $collection->add('a');
        $collection->add('b');
        static::assertEquals(2, $collection->count());
    }

    public function testGetNumericKeys(): void
    {
        $collection = new TestCollection();
        static::assertEquals([]$collection->getKeys());

        $collection->add('a');
        $collection->add('b');
        static::assertEquals([0, 1]$collection->getKeys());
    }

    public function testHasWithNumericKey(): void
    {
        $collection = new TestCollection();
        static::assertFalse($collection->has(0));

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