This concerns, for example, field "Title".

Notice: Undefined index: type in colorbox_node_field_formatter_settings_form_alter() (line 266 of colorbox_node/colorbox_node.module).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

iLLin’s picture

Category: Task » Bug report
Status: Patch (to be ported) » Active

I cannot duplicate this and I have reviewed that function:

/**
 * Implements hook_field_formatter_settings_form_alter().
 */
function colorbox_node_field_formatter_settings_form_alter(&$settings_form, $context) {
  // Integration with the entityreference module
  if ($context['instance']['display'][$context['view_mode']]['type'] == 'entityreference_label') {
    $display = $context['instance']['display'][$context['view_mode']];
    $settings = $display['settings'];

    $settings_form['colorbox_node_link'] = array(
      '#title' => t('Open in a Colorbox'),
      '#type' => 'checkbox',
      '#default_value' => $settings['colorbox_node_link'],
      '#dependency' => array(
        'edit-fields-field-entity-settings-edit-form-settings-link' => array(1),
      ),
    );
    $settings_form['colorbox_node_width'] = array(
      '#type' => 'textfield',
      '#title' => t('Colorbox Width'),
      '#default_value' => !empty($settings['colorbox_node_width']) ? $settings['colorbox_node_width'] : '600',
      '#dependency' => array(
        'edit-fields-field-entity-settings-edit-form-settings-colorbox-node-link' => array(1),
      ),
      '#dependency_count' => 1,
      '#weight' => 1,
    );
    $settings_form['colorbox_node_height'] = array(
      '#type' => 'textfield',
      '#title' => t('Colorbox Height'),
      '#default_value' => !empty($settings['colorbox_node_height']) ? $settings['colorbox_node_height'] : '600',
      '#dependency' => array(
        'edit-fields-field-entity-settings-edit-form-settings-colorbox-node-link' => array(1),
      ),
      '#dependency_count' => 1,
      '#weight' => 2,
    );
    $settings_form['colorbox_node_classes'] = array(
      '#title' => t('Classes to add to the anchor tag (in addition to "colorbox-node")'),
      '#type' => 'textfield',
      '#default_value' => $settings['colorbox_node_classes'],
      '#dependency' => array(
        'edit-fields-field-entity-settings-edit-form-settings-colorbox-node-link' => array(1),
      ),
      '#weight' => 3,
    );
  }
}

Which follows the field_formatter_settings module hook API.

/**
 * Alter the form elements for a formatter's settings.
 *
 * @param $settings_form
 *   The settings form array from the field module's implementation of
 *   hook_field_formatter_settings().
 * @param $context
 *   An array of additional context for the settings form, containing:
 *   - module: The module providing the formatter being configured.
 *   - formatter: The definition array of the formatter being configured. Note
 *     that this does not contain the machine name of the formatter. This can
 *     be found in:
 *     @code
 *     $context['instance']['display'][$context['view_mode']]['type']
 *     @endcode
 *   - field: The field structure being configured.
 *   - instance: The instance structure being configured.
 *   - view_mode: The view mode being configured.
 *   - form: The (entire) configuration form array, which will usually have no
 *     use here.
 *   - form_state: The form state of the (entire) configuration form.
 *
 * @see hook_field_formatter_settings()
 */
function hook_field_formatter_settings_form_alter(array &$settings_form, array $context) {

}

Not sure about the reference for field "title" or what that means. Can you elaborate a little bit more?

Bogomazik’s picture

I have Display Suite installed. When I manage display any of content type and click edit formatter settings of the field "Title" I get this notice.
"Title" isn't have $context['instance']['display'][$context['view_mode']]['type']. I think because "Title" is a property.
I added
isset($context['instance']['display'][$context['view_mode']]['type']

Does that make sense?

iLLin’s picture

Yup, just haven't ran across that and I normally use isset... This is what I get for following the API instructions haha. I'll get a fix in soon.

Bogomazik’s picture

I`ve added the patch...

Thanks!

PrineShazar’s picture

Im having the same issue and patch #4 fixed it. Thank you.

I have DS installed too.

  • iLLin committed 773b01a on 7.x-3.x
    Issue #2479511 by Bogomazik: Undefined index: type in...
iLLin’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.