Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FieldBlock.php

function FieldBlock::entityFieldHasDefaultValue

Checks whether there is a default value set on the field.

Return value

bool TRUE if default value set, FALSE otherwise.

1 call to FieldBlock::entityFieldHasDefaultValue()
FieldBlock::blockAccess in core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
Indicates whether the block should be shown.

File

core/modules/layout_builder/src/Plugin/Block/FieldBlock.php, line 418

Class

FieldBlock
Provides a block that renders a field from an entity.

Namespace

Drupal\layout_builder\Plugin\Block

Code

protected function entityFieldHasDefaultValue() : bool {
    $entity = $this->getEntity();
    $field = $entity->get($this->fieldName);
    $definition = $field->getFieldDefinition();
    if ($definition->getDefaultValue($entity)) {
        return TRUE;
    }
    // @todo Remove special handling of image fields after
    // https://www.drupal.org/project/drupal/issues/3005528.
    if ($definition->getType() !== 'image') {
        return FALSE;
    }
    $default_image = $definition->getSetting('default_image');
    // If we are dealing with a configurable field, look in both instance-level
    // and field-level settings.
    if (empty($default_image['uuid']) && $definition instanceof FieldConfigInterface) {
        $default_image = $definition->getFieldStorageDefinition()
            ->getSetting('default_image');
    }
    return !empty($default_image['uuid']);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal