class DefaultLanguageItem

Same name in other branches
  1. 9 core/modules/language/src/DefaultLanguageItem.php \Drupal\language\DefaultLanguageItem
  2. 8.9.x core/modules/language/src/DefaultLanguageItem.php \Drupal\language\DefaultLanguageItem
  3. 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
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FieldItemBase::calculateDependencies public static function Overrides FieldItemInterface::calculateDependencies 2
FieldItemBase::calculateStorageDependencies public static function Overrides FieldItemInterface::calculateStorageDependencies
FieldItemBase::defaultFieldSettings public static function Overrides FieldItemInterface::defaultFieldSettings 6
FieldItemBase::defaultStorageSettings public static function Overrides FieldItemInterface::defaultStorageSettings 9
FieldItemBase::delete public function Overrides FieldItemInterface::delete 2
FieldItemBase::deleteRevision public function Overrides FieldItemInterface::deleteRevision
FieldItemBase::fieldSettingsForm public function Overrides FieldItemInterface::fieldSettingsForm 6
FieldItemBase::fieldSettingsFromConfigData public static function Overrides FieldItemInterface::fieldSettingsFromConfigData 1
FieldItemBase::fieldSettingsSummary public static function Overrides FieldItemInterface::fieldSettingsSummary
FieldItemBase::fieldSettingsToConfigData public static function Overrides FieldItemInterface::fieldSettingsToConfigData 1
FieldItemBase::getEntity public function Overrides FieldItemInterface::getEntity
FieldItemBase::getFieldDefinition public function Overrides FieldItemInterface::getFieldDefinition
FieldItemBase::getLangcode public function Overrides FieldItemInterface::getLangcode
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 Overrides FieldItemInterface::mainPropertyName 8
FieldItemBase::onDependencyRemoval public static function Overrides FieldItemInterface::onDependencyRemoval
FieldItemBase::postSave public function Overrides FieldItemInterface::postSave 2
FieldItemBase::preSave public function Overrides FieldItemInterface::preSave 6
FieldItemBase::storageSettingsForm public function Overrides FieldItemInterface::storageSettingsForm 7
FieldItemBase::storageSettingsFromConfigData public static function Overrides FieldItemInterface::storageSettingsFromConfigData 2
FieldItemBase::storageSettingsSummary public static function Overrides FieldItemInterface::storageSettingsSummary
FieldItemBase::storageSettingsToConfigData public static function Overrides FieldItemInterface::storageSettingsToConfigData 2
FieldItemBase::view public function Overrides FieldItemInterface::view
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.
Overrides Map::writePropertyValue
FieldItemBase::__construct public function Overrides TypedData::__construct 2
FieldItemBase::__get public function Overrides FieldItemInterface::__get 2
FieldItemBase::__isset public function Overrides FieldItemInterface::__isset
FieldItemBase::__set public function Overrides FieldItemInterface::__set 1
FieldItemBase::__unset public function Overrides FieldItemInterface::__unset
LanguageItem::generateSampleValue public static function Overrides FieldItemBase::generateSampleValue
LanguageItem::getPossibleOptions public function Overrides OptionsProviderInterface::getPossibleOptions
LanguageItem::getPossibleValues public function Overrides OptionsProviderInterface::getPossibleValues
LanguageItem::getSettableOptions public function Overrides OptionsProviderInterface::getSettableOptions
LanguageItem::getSettableValues public function Overrides OptionsProviderInterface::getSettableValues
LanguageItem::onChange public function Overrides Map::onChange
LanguageItem::propertyDefinitions public static function Overrides FieldItemInterface::propertyDefinitions
LanguageItem::schema public static function Overrides FieldItemInterface::schema
LanguageItem::setValue public function Overrides FieldItemBase::setValue
Map::$definition protected property The data definition. Overrides TypedData::$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 Overrides ComplexDataInterface::get
Map::getIterator public function
Map::getProperties public function Overrides ComplexDataInterface::getProperties
Map::getString public function Overrides TypedData::getString
Map::getValue public function Overrides TypedData::getValue
Map::isEmpty public function Overrides ComplexDataInterface::isEmpty 16
Map::set public function Overrides ComplexDataInterface::set
Map::toArray public function Overrides ComplexDataInterface::toArray 1
Map::__clone public function Magic method: Implements a deep clone.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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. 2
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 Overrides TypedDataInterface::createInstance
TypedData::getConstraints public function Overrides TypedDataInterface::getConstraints 8
TypedData::getDataDefinition public function Overrides TypedDataInterface::getDataDefinition
TypedData::getName public function Overrides TypedDataInterface::getName
TypedData::getParent public function Overrides TypedDataInterface::getParent
TypedData::getPluginDefinition public function Overrides PluginInspectionInterface::getPluginDefinition
TypedData::getPluginId public function Overrides PluginInspectionInterface::getPluginId
TypedData::getPropertyPath public function Overrides TypedDataInterface::getPropertyPath
TypedData::getRoot public function Overrides TypedDataInterface::getRoot
TypedData::setContext public function Overrides TypedDataInterface::setContext
TypedData::validate public function Overrides TypedDataInterface::validate
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager. 2
TypedDataTrait::setTypedDataManager public function Sets the typed data manager. 2

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