Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The issue is in the following function:
field_collection_i18n_string_list_field_alter(...)
in the block
foreach ($instance['display'] as $view_mode => $display) {
if ($display['type'] != 'field_collection_fields') {
$display['settings'] += array('edit' => 'edit', 'delete' => 'delete', 'add' => 'add');
$properties['field'][$instance['field_name']][$instance['bundle']]['setting_edit'] = array(
'title' => t('Edit link title'),
'string' => $display['settings']['edit'],
);
$properties['field'][$instance['field_name']][$instance['bundle']]['setting_delete'] = array(
'title' => t('Delete link title'),
'string' => $display['settings']['delete'],
);
$properties['field'][$instance['field_name']][$instance['bundle']]['setting_add'] = array(
'title' => t('Add link title'),
'string' => $display['settings']['add'],
);
}
}
the preexistence of $display['settings'] is not verified prior to merging the array.
I propose to add a check for the existence of the array. settings should be an array, but in case it is not, we wipe it clean and provide it.
/**
* Implements hook_i18n_string_list_{textgroup}_alter().
*/
function field_collection_i18n_string_list_field_alter(&$properties, $type, $instance) {
if ($type == 'field_instance') {
$field = field_info_field($instance['field_name']);
if ($field['type'] == 'field_collection' && !empty($instance['display'])) {
foreach ($instance['display'] as $view_mode => $display) {
if ($display['type'] != 'field_collection_fields') {
if (! isset($display['settings']) || ! is_array($display['settings'])) {
$display['settings'] = array();
}
$display['settings'] += array('edit' => 'edit', 'delete' => 'delete', 'add' => 'add');
$properties['field'][$instance['field_name']][$instance['bundle']]['setting_edit'] = array(
'title' => t('Edit link title'),
'string' => $display['settings']['edit'],
);
$properties['field'][$instance['field_name']][$instance['bundle']]['setting_delete'] = array(
'title' => t('Delete link title'),
'string' => $display['settings']['delete'],
);
$properties['field'][$instance['field_name']][$instance['bundle']]['setting_add'] = array(
'title' => t('Add link title'),
'string' => $display['settings']['add'],
);
}
}
}
}
}
Comments
Comment #1
jmuzz CreditAttribution: jmuzz commentedI'm not sure it shouldn't show an error if the display settings aren't there. When would this happen? Can you provide steps to reproduce?