Notice: Undefined index: country in countries_field_formatter_view() (line 234 of /home/bpcodnku/public_html/sites/all/modules/cintrib/countries/countries.fields.inc). =>

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vnantonov created an issue. See original summary.

vnantonov’s picture

FileSize
54.07 KB
vnantonov’s picture

i work with Country Field Version: 7.x-1.0
Country Icons API Version: 7.x-2.0-beta1
Country Icons: Shiny Version: 7.x-2.0+0-dev

Alan D.’s picture

did you disable a country or add & delete a new one?

Does editing and saving the content item that generates the error helps?

vnantonov’s picture

when disable countries module stop error but i want country flag

vnantonov’s picture

version on drupal Drupal 7.54

vnantonov’s picture

countries module is broken all icon and flag module i test all version on countries module but this error is same on all

Alan D.’s picture

I've tried on Countries 2.x with the same icon modules, no issues.

I thought that it could have been a country that you disabled, (i.e. edit USA and disable it), but the module still works in that case.

So I guess something particular to your setup is causing this.

i.e. countries_field_prepare_view() will at least populate the index country with either a real country object or false, so the notice should never show.

So maybe see if countries_field_prepare_view() gets called, and if not, try a full cache flush on the page and see if that gets called.

/**
 * Implements hook_field_prepare_view().
 */
function countries_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
dpm($entities);
// $items[$id][$delta]['country'] not set at this stage.
dpm($items);
  foreach ($entities as $id => $entity) {
    foreach ($items[$id] as $delta => $item) {
......
    }
  }
// $items[$id][$delta]['country'] should be set now.
dpm($items);
}
harshita29’s picture

Status: Active » Needs review
FileSize
493 bytes

Hi,
Here is the patch for the same.

Alan D.’s picture

Status: Needs review » Postponed (maintainer needs more info)

If it gets to the formatter and is not set, something is badly broken already.

I can not understand from the request if;

  • everything is broken, which in that case there is a major compatibility issue with some other module or caching system, or;
  • this is affecting a single page / country where the module is storing an invalid DB key.

Things work on a clean install without issue, so it is impossible to help without being able to replicate.

DS, Panels, and similar modules could be interacting here too.

Alan D.’s picture

A similar patch could be used for avoiding the PHP notice and logging possible errors.

This will not be committed as it is just a band aid that is obscuring the real issue....

  foreach ($items as $delta => $item) {
    if (empty($item['country'])) {
      $item['country'] = country_load($item['iso2']);
      if (!$item['country']) {
        list($id) = entity_extract_ids($entity_type, $entity);
        watchdog('countries', 'Invalid or missing country detected in countries_field_formatter_view().' 
            . '<ul><li>ISO2 was %iso2</li><li>Entity type: %entity_type</li><li>Entity ID: %id</li>', array(
                '%iso2' => $item['iso2'],
                '%entity_type' => $entity_type,
                '%id' => $id,
            ));
        continue;
      }
    }
    $country = $item['country'];
    if (empty($country)) {
      continue;
    }