Returns the Widget plugin for the instance.
Drupal\field\Plugin\Type\Widget\WidgetInterface The Widget plugin to be used for the instance.
public function getWidget() {
if (empty($this->widget)) {
$widget_properties = $this->definition['widget'];
// Let modules alter the widget properties.
$context = array(
'entity_type' => $this->definition['entity_type'],
'bundle' => $this->definition['bundle'],
'field' => field_info_field($this->definition['field_name']),
'instance' => $this,
);
drupal_alter(array(
'field_widget_properties',
'field_widget_properties_' . $this->definition['entity_type'],
), $widget_properties, $context);
$options = array(
'instance' => $this,
'type' => $widget_properties['type'],
'settings' => $widget_properties['settings'],
'weight' => $widget_properties['weight'],
);
$this->widget = drupal_container()
->get('plugin.manager.field.widget')
->getInstance($options);
}
return $this->widget;
}