class DefaultLanguageItem

Same name and namespace in other branches
  1. 11.x core/modules/language/src/DefaultLanguageItem.php \Drupal\language\DefaultLanguageItem

Alternative plugin implementation of the 'language' field type.

Replaces the Core 'language' entity field type implementation, changes the default values used.

Required settings are:

  • target_type: The entity type to reference.

Hierarchy

Expanded class hierarchy of DefaultLanguageItem

See also

language_field_info_alter().

File

core/modules/language/src/DefaultLanguageItem.php, line 20

Namespace

Drupal\language
View source
class DefaultLanguageItem extends LanguageItem {
  
  /**
   * {@inheritdoc}
   */
  public function applyDefaultValue($notify = TRUE) {
    // Default to LANGCODE_NOT_SPECIFIED.
    $langcode = Language::LANGCODE_NOT_SPECIFIED;
    if ($entity = $this->getEntity()) {
      $langcode = $this->getDefaultLangcode($entity);
    }
    // Always notify otherwise default langcode will not be set correctly.
    $this->setValue([
      'value' => $langcode,
    ], TRUE);
    return $this;
  }
  
  /**
   * Provides default language code of given entity.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity whose language code to be loaded.
   *
   * @return string
   *   A string language code.
   */
  public function getDefaultLangcode(EntityInterface $entity) {
    return language_get_default_langcode($entity->getEntityTypeId(), $entity->bundle());
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DefaultLanguageItem::applyDefaultValue public function Applies the default value. Overrides LanguageItem::applyDefaultValue
DefaultLanguageItem::getDefaultLangcode public function Provides default language code of given entity.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function
DependencySerializationTrait::__wakeup public function #[\ReturnTypeWillChange]
FieldItemBase::calculateDependencies public static function 1
FieldItemBase::calculateDependencies public static function 1
FieldItemBase::calculateStorageDependencies public static function
FieldItemBase::defaultFieldSettings public static function 1
FieldItemBase::defaultFieldSettings public static function 1
FieldItemBase::defaultStorageSettings public static function 1
FieldItemBase::defaultStorageSettings public static function 1
FieldItemBase::delete public function 1
FieldItemBase::delete public function 1
FieldItemBase::deleteRevision public function
FieldItemBase::fieldSettingsForm public function 1
FieldItemBase::fieldSettingsForm public function 1
FieldItemBase::fieldSettingsFromConfigData public static function 1
FieldItemBase::fieldSettingsFromConfigData public static function 1
FieldItemBase::fieldSettingsToConfigData public static function 1
FieldItemBase::fieldSettingsToConfigData public static function 1
FieldItemBase::getEntity public function
FieldItemBase::getFieldDefinition public function
FieldItemBase::getLangcode public function
FieldItemBase::getSetting protected function Returns the value of a field setting.
FieldItemBase::getSettings protected function Returns the array of field settings.
FieldItemBase::mainPropertyName public static function 1
FieldItemBase::mainPropertyName public static function 1
FieldItemBase::onDependencyRemoval public static function
FieldItemBase::postSave public function
FieldItemBase::preSave public function
FieldItemBase::storageSettingsForm public function 1
FieldItemBase::storageSettingsForm public function 1
FieldItemBase::storageSettingsFromConfigData public static function 1
FieldItemBase::storageSettingsFromConfigData public static function 1
FieldItemBase::storageSettingsToConfigData public static function 1
FieldItemBase::storageSettingsToConfigData public static function 1
FieldItemBase::view public function
FieldItemBase::writePropertyValue protected function Different to the parent Map class, we avoid creating property objects as
far as possible in order to optimize performance. Thus we just update
$this->values if no property object has been created yet.
FieldItemBase::__construct public function
FieldItemBase::__get public function 1
FieldItemBase::__get public function 1
FieldItemBase::__isset public function
FieldItemBase::__set public function
FieldItemBase::__unset public function
LanguageItem::generateSampleValue public static function
LanguageItem::getPossibleOptions public function
LanguageItem::getPossibleValues public function
LanguageItem::getSettableOptions public function
LanguageItem::getSettableValues public function
LanguageItem::onChange public function
LanguageItem::propertyDefinitions public static function
LanguageItem::schema public static function
LanguageItem::setValue public function
Map::$definition protected property The data definition.
Map::$properties protected property The array of properties.
Map::$values protected property An array of values for the contained properties.
Map::get public function
Map::getIterator public function #[\ReturnTypeWillChange]
Map::getProperties public function
Map::getString public function
Map::getValue public function
Map::isEmpty public function 3
Map::isEmpty public function 3
Map::set public function
Map::toArray public function
Map::__clone public function Magic method: Implements a deep clone.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TypedData::$name protected property The property name.
TypedData::$parent protected property The parent typed data object.
TypedData::createInstance public static function
TypedData::getConstraints public function 2
TypedData::getConstraints public function 2
TypedData::getDataDefinition public function
TypedData::getName public function
TypedData::getParent public function
TypedData::getPluginDefinition public function
TypedData::getPluginId public function
TypedData::getPropertyPath public function
TypedData::getRoot public function
TypedData::setContext public function
TypedData::validate public function
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager.
TypedDataTrait::setTypedDataManager public function Sets the typed data manager.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.