I've got a view of countries. I've got countryicons and countryicons_shiny enabled. I'm looking for a way to include a country's flag icon in my view of countries. Is that do-able? I don't see the views integration in either countries, or countryicons.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan D.’s picture

can u supply an export of the view for me to take a look at it please

johnv’s picture

@ezeedub, please examine the three attached printscreens, of my taxonomy view with a country field. I think this is what you mean.

Alan D.’s picture

I think that ezeedub has an actual country view, otherwise it is fairly hard to miss the formatter options for the country field. Must be fairly easy, I walked someone through creating the view here: #2051015: How to add Country Icons to the administrative table of countries, but can not see how the icon is inserted with PHP or a custom template that runs some PHP.

One way is (quick hack and would not be the final version):

countries.info

files[] = views/views_handler_field_countries_flag.inc

views/countries.views.inc

  $data['countries_country']['iso2_list'] = array(
    ....
  );
## Add this bit
  // Adds a formatter option for the country icon.
  if (module_exists('countryicons')) {
    $data['countries_country']['iso2_flag'] = array(
      'title' => t('Country Flag'),
      'help' => t('Flag provided by the Country Icons module.'),
      'real field' => 'iso2',
      'field' => array(
        'handler' => 'views_handler_field_countries_flag',
        'click sortable' => FALSE,
      ),
    );
  }

and the attached file, renamed to views/views_handler_field_countries_flag.inc

Alan D.’s picture

Simple field listing:

Producing:

Alan D.’s picture

Title: Add relationship to flag icon for view of type country? » Provide Country Flag views field handler.
Category: support » feature

In #2051015: How to add Country Icons to the administrative table of countries, that user added a computed field that stored the icon and that allowed him to render the flag just like any other field.

I'll keep this issue open for a views field handler ;)

roball’s picture

A views field handler implemented by the Countries module would be an awesome addition! This would no longer need the Computed Field module to be involved. Very user-friendly :-)

ezeedub’s picture

@Alan D Yes, I have a view of countries. Your solution in #3 is exactly what I was thinking. Why do you think it's temporary?

Here's a patch version. I removed the continent_code checkbox. I'm also thinking we could remove the Icon suffix here, since there are already views fields for those properties.

ezeedub’s picture

Status: Active » Needs review

forgot to change status

Status: Needs review » Needs work

The last submitted patch, views_flag_field-2070267-7.patch, failed testing.

Alan D.’s picture

Why do you think it's temporary?

Because it duplicates a significant amount of code... This should be handled by a helper function so that both of these forms stay sync'ed ;)

ezeedub’s picture

Ah, that. Good point by you! :)

earelin’s picture

Issue summary: View changes
FileSize
3.72 KB

I have updated the patch. Now is not using deprecated function countries_get_country and maybe is going to pass testing.

earelin’s picture

Error fixed in the rendering fuction

Alan D.’s picture

Status: Needs work » Needs review

Needs review will trigger the testing (albeit that isn't that comprehensive)

The last submitted patch, 12: views_flag_field-2070267-8.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 13: views_flag_field-2070267-9.patch, failed testing.

earelin’s picture

Version: 7.x-2.1 » 7.x-2.3

Status: Needs work » Needs review
earelin’s picture

I have updated the issue to the last version, the patch is not for 2.1. Now it has passed the test.

roball’s picture

Patches should however always be made against the current Git branch (7.x-2.x), which corresponds to the 7.x-2.x-dev release snapshot.