Define own Galleryformatter style

Last updated on
30 April 2025

If you use galleryformatter, sometimes you need own style, not just a contrib Greenarrow. I'd like to answer how to add this style.

  1. first you need the implementation of hook_galleryformatter_styles
    /**
     * Implementation of hook_galleryformatter_styles().
     *
     * This hook allows other modules to create additional tab styles for
     * the galleryformatter module.
     *
     * @return array
     *   An array of key => value pairs suitable for inclusion as the #options in a
     *   select or radios form element. Each key must be the location of a css
     *   file for a gallery formatter style. Each value should be the name of the style.
     */
    function mymodule_galleryformatter_styles() {
      $gallerystyles_directory = drupal_get_path('module', 'mymodule') . '/gallerystyles';
      $files = file_scan_directory($gallerystyles_directory, '/\.css$/');
      $gallerystyles = array();
      foreach ($files as $file) {
        // Skip RTL files.
        if (!strpos($file->name, '-rtl')) {
          $gallerystyles[$file->uri] = drupal_ucfirst($file->name);
        }
      }
      return $gallerystyles;
    }
    
  2. add gallerystyles folder in to your theme or module
  3. add custom mymodule.css file.
  4. clean Theme registry cache table, or all cache tables
  5. go to your node type manage display page, and edit your image field, and set Mymodule style for image
  6. save

You just need to write some css code for style it.

Help improve this page

Page status: Not set

You can: