getKey example

// Only alter the query if the active workspace is not the default one and     // the entity type is supported.     if ($this->workspaceManager->hasActiveWorkspace() && $this->workspaceManager->isEntityTypeSupported($this->entityType)) {
      $active_workspace = $this->workspaceManager->getActiveWorkspace();
      $this->sqlQuery->addMetaData('active_workspace_id', $active_workspace->id());
      $this->sqlQuery->addMetaData('simple_query', FALSE);

      // LEFT JOIN 'workspace_association' to the base table of the query so we       // can properly include live content along with a possible workspace       // revision.       $id_field = $this->entityType->getKey('id');
      $this->sqlQuery->leftJoin('workspace_association', 'workspace_association', "[%alias].[target_entity_type_id] = '{$this->entityTypeId}' AND [%alias].[target_entity_id] = [base_table].[$id_field] AND [%alias].[workspace] = '{$active_workspace->id()}'");
    }

    return $this;
  }

  /** * {@inheritdoc} */
  public function isSimpleQuery() {
    // We declare that this is not a simple query in
$headersToBypass = ['from', 'sender', 'to', 'cc', 'bcc', 'subject', 'reply-to', 'content-type', 'accept', 'api-key'];
        foreach ($headers->all() as $name => $header) {
            if (\in_array($name$headersToBypass, true)) {
                continue;
            }
            if ($header instanceof TagHeader) {
                $headersAndTags['tags'][] = $header->getValue();

                continue;
            }
            if ($header instanceof MetadataHeader) {
                $headersAndTags['headers']['X-Mailin-'.ucfirst(strtolower($header->getKey()))] = $header->getValue();

                continue;
            }
            if ('templateid' === $name) {
                $headersAndTags[$header->getName()] = (int) $header->getValue();

                continue;
            }
            if ('params' === $name) {
                $headersAndTags[$header->getName()] = $header->getParameters();

                

class EntityContentComplete extends EntityContentBase {

  use EntityFieldDefinitionTrait;

  /** * {@inheritdoc} */
  public function getIds() {
    $ids = [];
    $id_key = $this->getKey('id');
    $ids[$id_key] = $this->getDefinitionFromEntity($id_key);

    $revision_key = $this->getKey('revision');
    if ($revision_key) {
      $ids[$revision_key] = $this->getDefinitionFromEntity($revision_key);
    }

    $langcode_key = $this->getKey('langcode');
    if ($langcode_key) {
      $ids[$langcode_key] = $this->getDefinitionFromEntity($langcode_key);
    }

    

        if (isset($this->skippedTests[__FUNCTION__])) {
            $this->markTestSkipped($this->skippedTests[__FUNCTION__]);
        }

        $cache = $this->createCachePool();
        $cache->clear();

        $value = mt_rand();

        $this->assertSame($value$cache->get('foo', function DCacheItem $item) use ($value) {
            $this->assertSame('foo', $item->getKey());

            return $value;
        }));

        $item = $cache->getItem('foo');
        $this->assertSame($value$item->get());

        $isHit = true;
        $this->assertSame($value$cache->get('foo', function DCacheItem $item) use (&$isHit) { $isHit = false; }, 0));
        $this->assertTrue($isHit);

        
public function testFromIterableArrayOfAssocArray(): void
    {
        $mappingFoo = ['key' => 'foo', 'mappedKey' => 'bar'];
        $mappingAsdf = ['key' => 'asdf', 'mappedKey' => 'zxcv'];
        $idMapping = 'id';
        $mappingCollection = MappingCollection::fromIterable([$mappingFoo$mappingAsdf$idMapping]);

        static::assertCount(3, $mappingCollection);

        $mappingFoo = $mappingCollection->get('foo');
        static::assertInstanceOf(Mapping::class$mappingFoo);
        static::assertSame('foo', $mappingFoo->getKey());

        $mappingAsdf = $mappingCollection->get('asdf');
        static::assertInstanceOf(Mapping::class$mappingAsdf);
        static::assertSame('asdf', $mappingAsdf->getKey());

        $idMapping = $mappingCollection->get('id');
        static::assertInstanceOf(Mapping::class$idMapping);
        static::assertSame('id', $idMapping->getKey());
        static::assertNull($idMapping->getDefaultValue());

        $idMappedKey = $mappingCollection->getMapped('id');
        

      $this->assertTrue(isset($entity->name)new FormattableMarkup('%entity_type: Name field is set.', ['%entity_type' => $entity_type]));
      $this->assertTrue($entity->name->isEmpty()new FormattableMarkup('%entity_type: Name field is set.', ['%entity_type' => $entity_type]));
      $this->assertCount(0, $entity->name, new FormattableMarkup('%entity_type: Name field contains no items.', ['%entity_type' => $entity_type]));
      $this->assertSame([]$entity->name->getValue()new FormattableMarkup('%entity_type: Name field value is an empty array.', ['%entity_type' => $entity_type]));
      $this->assertFalse(isset($entity->name[0])new FormattableMarkup('%entity_type: Name field item is not set.', ['%entity_type' => $entity_type]));
      $this->assertFalse(isset($entity->name[0]->value)new FormattableMarkup('%entity_type: First name item value is not set.', ['%entity_type' => $entity_type]));
      $this->assertFalse(isset($entity->name->value)new FormattableMarkup('%entity_type: Name value is not set.', ['%entity_type' => $entity_type]));
    }

    // Access the language field.     $langcode_key = $this->entityTypeManager->getDefinition($entity_type)->getKey('langcode');
    $this->assertEquals($langcode$entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Language code can be read.', ['%entity_type' => $entity_type]));
    $this->assertEquals(\Drupal::languageManager()->getLanguage($langcode)$entity->{$langcode_key}->language, new FormattableMarkup('%entity_type: Language object can be read.', ['%entity_type' => $entity_type]));

    // Change the language by code.     $entity->{$langcode_key}->value = \Drupal::languageManager()->getDefaultLanguage()->getId();
    $this->assertEquals(\Drupal::languageManager()->getDefaultLanguage()->getId()$entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Language code can be read.', ['%entity_type' => $entity_type]));
    $this->assertEquals(\Drupal::languageManager()->getDefaultLanguage()$entity->{$langcode_key}->language, new FormattableMarkup('%entity_type: Language object can be read.', ['%entity_type' => $entity_type]));

    // Revert language by code then try setting it by language object.     $entity->{$langcode_key}->value = $langcode;
    $entity->{$langcode_key}->language = \Drupal::languageManager()->getDefaultLanguage();
    


        $shop = $order->getShop();
        if (!$shop instanceof Shop) {
            throw new ModelNotFoundException(Shop::class$orderId);
        }

        $customerGroup = $customer->getGroup() ?? $this->container->get(ModelManager::class)->getRepository(Group::class)->findOneBy(['key' => self::DEFAULT_CUSTOMER_GROUP]);
        if (!$customerGroup instanceof Group) {
            throw new ModelNotFoundException(Group::class$orderId);
        }
        $customerGroupKey = $customerGroup->getKey();

        $area = $orderShippingAddress->getCountry()->getArea();
        $state = $orderShippingAddress->getState();
        $shopContext = $this->container->get('shopware_storefront.shop_context_factory')->create(
            $shop->getBaseUrl() ?? '',
            $shop->getId(),
            null,
            $customerGroupKey,
            $area ? $area->getId() : null,
            $orderShippingAddress->getCountry()->getId(),
            $state ? $state->getId() : null
        );

    return FALSE;
  }

  /** * {@inheritdoc} */
  public function getDefaultRevisionId($entity_type_id$entity_id) {
    if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
      $result = $storage->getQuery()
        ->currentRevision()
        ->condition($this->entityTypeManager->getDefinition($entity_type_id)->getKey('id')$entity_id)
        // No access check is performed here since this is an API function and         // should return the same ID regardless of the current user.         ->accessCheck(FALSE)
        ->execute();
      if ($result) {
        return key($result);
      }
    }
  }

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

  /** * {@inheritdoc} */
  public function label() {
    if (($label_key = $this->getEntityType()->getKey('label')) && isset($this->{$label_key})) {
      return $this->{$label_key};
    }
  }

  /** * {@inheritdoc} */
  public function toUrl($rel = 'canonical', array $options = []) {
    if ($this->id() === NULL) {
      throw new EntityMalformedException(sprintf('The "%s" entity cannot have a URI as it does not have an ID', $this->getEntityTypeId()));
    }

    

  public function testToUrlLinkTemplateAddForm($has_bundle_key$bundle_entity_type$bundle_key$expected_route_parameters) {
    $values = ['id' => $this->entityId, 'langcode' => $this->langcode];
    $entity = $this->getEntity(UrlTestEntity::class$values);
    $this->entityType->hasKey('bundle')->willReturn($has_bundle_key);
    $this->entityType->getBundleEntityType()->willReturn($bundle_entity_type);
    $this->entityType->getKey('bundle')->willReturn($bundle_key);
    $link_template = 'add-form';
    $this->registerLinkTemplate($link_template);

    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl($link_template);
    $this->assertUrl('entity.test_entity.add_form', $expected_route_parameters$entity, FALSE, $url);
  }

  /** * Provides data for testToUrlLinkTemplateAddForm(). * * @return array * An array of test cases for testToUrlLinkTemplateAddForm(). */

  protected $formBuilder;

  /** * {@inheritdoc} */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage) {
    parent::__construct($entity_type$storage);

    // Check if the entity type supports weighting.     if ($this->entityType->hasKey('weight')) {
      $this->weightKey = $this->entityType->getKey('weight');
    }
    $this->limit = FALSE;
  }

  /** * {@inheritdoc} */
  public function buildHeader() {
    $header = [];
    if (!empty($this->weightKey)) {
      $header['weight'] = t('Weight');
    }
$request['ConfigurationSetName'] = $header->getBodyAsString();
        }
        if ($header = $email->getHeaders()->get('X-SES-SOURCE-ARN')) {
            $request['FromEmailAddressIdentityArn'] = $header->getBodyAsString();
        }
        if ($email->getReturnPath()) {
            $request['FeedbackForwardingEmailAddress'] = $email->getReturnPath()->toString();
        }

        foreach ($email->getHeaders()->all() as $header) {
            if ($header instanceof MetadataHeader) {
                $request['EmailTags'][] = ['Name' => $header->getKey(), 'Value' => $header->getValue()];
            }
        }

        return new SendEmailRequest($request);
    }

    private function getRecipients(Email $email, Envelope $envelope): array
    {
        $emailRecipients = array_merge($email->getCc()$email->getBcc());

        return array_filter($envelope->getRecipients()fn (Address $address) => !\in_array($address$emailRecipients, true));
    }

  protected function loadRecords() {
    $prefix = $this->entityType->getConfigPrefix() . '.';
    $prefix_length = strlen($prefix);

    // Search the conditions for restrictions on configuration object names.     $filter_by_names = [];
    $has_added_restrictions = FALSE;
    $id_condition = NULL;
    $id_key = $this->entityType->getKey('id');
    if ($this->condition->getConjunction() == 'AND') {
      $lookup_keys = $this->entityType->getLookupKeys();
      $conditions = $this->condition->conditions();
      foreach ($conditions as $condition_key => $condition) {
        $operator = $condition['operator'] ?: (is_array($condition['value']) ? 'IN' : '=');
        if (is_string($condition['field']) && ($operator == 'IN' || $operator == '=')) {
          // Special case ID lookups.           if ($condition['field'] == $id_key) {
            $has_added_restrictions = TRUE;
            $ids = (array) $condition['value'];
            $filter_by_names[] = array_map(static function D$id) use ($prefix) {
              
if ($entity_information) {
      $params = [];
      if ($this->hasAggregate) {
        // Handle grouping, by retrieving the minimum entity_id.         $params = [
          'function' => 'min',
        ];
      }

      foreach ($entity_information as $info) {
        $entity_type = \Drupal::entityTypeManager()->getDefinition($info['entity_type']);
        $base_field = !$info['revision'] ? $entity_type->getKey('id') : $entity_type->getKey('revision');
        $this->addField($info['alias']$base_field, '', $params);
      }
    }

    // Add all fields to the query.     $this->compileFields($query);

    // Add groupby.     if ($groupby) {
      foreach ($groupby as $field) {
        // Handle group by of field without table alias to avoid ambiguous
/** * Determines the entity type's (internal) label field name. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity from which fields should be extracted. * * @return string * The label field name. */
  protected static function getLabelFieldName(EntityInterface $entity) {
    $label_field_name = $entity->getEntityType()->getKey('label');
    // Special handling for user entities that allows a JSON:API user agent to     // access the display name of a user. This is useful when displaying the     // name of a node's author.     // @see \Drupal\jsonapi\JsonApiResource\ResourceObject::extractContentEntityFields()     // @todo: eliminate this special casing in https://www.drupal.org/project/drupal/issues/3079254.     if ($entity->getEntityTypeId() === 'user') {
      $label_field_name = 'display_name';
    }
    return $label_field_name;
  }

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