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

Breadcrumb

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

class DefaultValue

Returns a given default value if the input is empty.

The default_value process plugin provides the ability to set a fixed default value. The plugin returns a default value if the input value is considered empty (NULL, FALSE, 0, '0', an empty string, or an empty array). The strict configuration key can be used to set the default only when the incoming value is NULL.

Available configuration keys:

  • default_value: The fixed default value to apply.
  • strict: (optional) Use strict value checking. Defaults to false.
    • FALSE: Apply default when input value is empty().
    • TRUE: Apply default when input value is NULL.

Example:


process:
  uid:
    -
      plugin: migration_lookup
      migration: users
      source: author
      no_stub: true
    -
      plugin: default_value
      default_value: 44

This will look up the source value of author in the users migration and if not found, set the destination property uid to 44.

Hierarchy

  • class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
    • class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
      • class \Drupal\migrate\ProcessPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\migrate\Plugin\MigrateProcessInterface
        • class \Drupal\migrate\Plugin\migrate\process\DefaultValue extends \Drupal\migrate\ProcessPluginBase

Expanded class hierarchy of DefaultValue

See also

\Drupal\migrate\Plugin\MigrateProcessInterface

1 string reference to 'DefaultValue'
DefaultValueSanitizeSniff::processFunctionCall in vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php
Processes this function call.

File

core/modules/migrate/src/Plugin/migrate/process/DefaultValue.php, line 45

Namespace

Drupal\migrate\Plugin\migrate\process
View source
class DefaultValue extends ProcessPluginBase {
    
    /**
     * {@inheritdoc}
     */
    public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
        if (!empty($this->configuration['strict'])) {
            return $value ?? $this->configuration['default_value'];
        }
        return $value ?: $this->configuration['default_value'];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DefaultValue::transform public function Performs the associated process. Overrides ProcessPluginBase::transform
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 5
PluginInspectionInterface::getPluginId public function Gets the plugin ID of the plugin instance. 2
ProcessPluginBase::$stopPipeline protected property Determines if processing of the pipeline is stopped.
ProcessPluginBase::isPipelineStopped public function Determines if the pipeline should stop processing. Overrides MigrateProcessInterface::isPipelineStopped
ProcessPluginBase::multiple public function Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface::multiple 3
ProcessPluginBase::reset public function Resets the internal data of a plugin. Overrides MigrateProcessInterface::reset
ProcessPluginBase::stopPipeline protected function Stops pipeline processing after this plugin finishes.

API Navigation

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