getEntityKey example

return $this->get('name')->value;
  }

  /** * {@inheritdoc} */
  public function getEntityKey($key) {
    // Typically this protected method is used internally by entity classes and     // exposed publicly through more specific getter methods. So that test cases     // are able to set and access entity keys dynamically, update the visibility     // of this method to public.     return parent::getEntityKey($key);
  }

}

    $this->state->set('entity_test.entity_keys', [
      'key_1' => 'test_field',
      'key_2' => 'test_field',
    ]);

    $this->installEntitySchema('entity_test');

    $entity = EntityTest::create([]);

    $entity->set('test_field', 'foo');
    $this->assertEquals('foo', $entity->getEntityKey('key_1'));
    $this->assertEquals('foo', $entity->getEntityKey('key_2'));

    $entity->set('test_field', 'bar');
    $this->assertEquals('bar', $entity->getEntityKey('key_1'));
    $this->assertEquals('bar', $entity->getEntityKey('key_2'));
  }

  /** * Data provider for ::testMultipleKeysCache. */
  public function multipleKeysCacheTestCases() {
    
->setLabel(new TranslatableMarkup('Published'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE)
        ->setDefaultValue(TRUE),
    ];
  }

  /** * {@inheritdoc} */
  public function isPublished() {
    return (bool) $this->getEntityKey('published');
  }

  /** * {@inheritdoc} */
  public function setPublished() {
    $key = $this->getEntityType()->getKey('published');
    $this->set($key, TRUE);

    return $this;
  }

  
/** * {@inheritdoc} */
  public function isDefaultTranslation() {
    return $this->activeLangcode === LanguageInterface::LANGCODE_DEFAULT;
  }

  /** * {@inheritdoc} */
  public function getRevisionId() {
    return $this->getEntityKey('revision');
  }

  /** * {@inheritdoc} */
  public function isTranslatable() {
    // Check the bundle is translatable, the entity has a language defined, and     // the site has more than one language.     $bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->entityTypeId);
    return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual();
  }

  
->setLabel(new TranslatableMarkup('User ID'))
        ->setSetting('target_type', 'user')
        ->setTranslatable($entity_type->isTranslatable())
        ->setDefaultValueCallback(static::class D '::getDefaultEntityOwner'),
    ];
  }

  /** * {@inheritdoc} */
  public function getOwnerId() {
    return $this->getEntityKey('owner');
  }

  /** * {@inheritdoc} */
  public function setOwnerId($uid) {
    $key = $this->getEntityType()->getKey('owner');
    $this->set($key$uid);

    return $this;
  }

  

class Media extends EditorialContentEntityBase implements MediaInterface {

  use EntityOwnerTrait;
  use StringTranslationTrait;

  /** * {@inheritdoc} */
  public function getName() {
    $name = $this->getEntityKey('label');

    if (empty($name)) {
      $media_source = $this->getSource();
      return $media_source->getMetadata($this$media_source->getPluginDefinition()['default_name_metadata_attribute']);
    }

    return $name;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.