public function FieldInstance::getWidget

Returns the Widget plugin for the instance.

Return value

Drupal\field\Plugin\Type\Widget\WidgetInterface The Widget plugin to be used for the instance.

File

drupal/core/modules/field/lib/Drupal/field/FieldInstance.php, line 52
Definition of Drupal\field\FieldInstance.

Class

FieldInstance
Class for field instance objects.

Namespace

Drupal\field

Code

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;
}