Ejemplo n.º 1
0
/**
 * Allow modules to add settings to field formatters provided by other modules.
 *
 * @param \Drupal\Core\Field\FormatterInterface $plugin
 *   The instantiated field formatter plugin.
 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
 *   The field definition.
 * @param $view_mode
 *   The entity view 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\DisplayOverView.
 */
function hook_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, $form, $form_state)
{
    $element = array();
    // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field
    // formatters.
    if ($plugin->getPluginId() == 'foo_formatter') {
        $element['my_setting'] = array('#type' => 'checkbox', '#title' => t('My setting'), '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'));
    }
    return $element;
}