You are here

public static function DateRangeDurationWidget::create in Datetime Extras 8

Creates an instance of the plugin.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The container to pull out services used in the plugin.

array $configuration: A configuration array containing information about the plugin instance.

string $plugin_id: The plugin ID for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Return value

static Returns an instance of this plugin.

Overrides DateRangeDefaultWidget::create

File

src/Plugin/Field/FieldWidget/DateRangeDurationWidget.php, line 58

Class

DateRangeDurationWidget
Plugin implementation of the 'daterange_duration' widget.

Namespace

Drupal\datetime_extras\Plugin\Field\FieldWidget

Code

public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
  $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);

  // Use setter injection to be immune from changes to the parent constructor.
  // @see https://www.previousnext.com.au/blog/safely-extending-drupal-8-plugin-classes-without-fear-of-constructor-changes
  $instance
    ->setDurationService($container
    ->get('duration_field.service'));
  $instance
    ->setGranularityService($container
    ->get('duration_field.granularity.service'));
  return $instance;
}