예제 #1
0
/**
 * Allow modules to add settings to field widgets provided by other modules.
 *
 * @param \Drupal\Core\Field\WidgetInterface $plugin
 *   The instantiated field widget plugin.
 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
 *   The field definition.
 * @param $form_mode
 *   The entity form mode.
 * @param array $form
 *   The (entire) configuration form array.
 * @param array $form_state
 *   The form state.
 *
 * @return array
 *   Returns the form array to be built.
 *
 * @see \Drupal\field_ui\FormDisplayOverView.
 */
function hook_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, $form_state)
{
    $element = array();
    // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field
    // widgets.
    if ($plugin->getPluginId() == 'foo_widget') {
        $element['my_setting'] = array('#type' => 'checkbox', '#title' => t('My setting'), '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'));
    }
    return $element;
}
 /**
  * Checks if a widget is supported.
  */
 public static function isWidgetSupported(WidgetInterface $widget)
 {
     return in_array($widget->getPluginId(), static::supportedWidgets());
 }