Provide support for callback in render() method

Created on 15 July 2011, almost 14 years ago
Updated 11 June 2025, 2 days ago

Hi,
I have been developing JW Player module with other colleagues. As part of project architecture, we decided to make JW Player presentation layer , providing predefined presets, skins and other configurations. All this while allowing file and media modules to do the actual heavy lifting work of uploading videos etc.

Our intention is for JW Player to provide presets that are available to styles. This is where we have hit roadblock.

The current support for image styles with ability to define effects, crop etc is great, however when it comes to Videos, presentation of videos is much more complex with things like, what skin to use, aspect ratio of the video, if there needs to be a thumbnail image etc. I am using video as an example, the same thing applies to other asset types such as audio.

I would like to suggest abstraction of these and allow other modules such as JW Player to define how the display of videos are to be rendered via presets.

Below is how i would like to implement

  1. is to be extended so that other modules can define a "render callback" attribute along with each preset, e.g JW Player would implement hook_styles_default_presets() as
    function jw_player_styles_default_presets() {
      $containers = array();
      $presets = _jw_player_styles_presets();
    
      return array(
        'file' => array(
          'containers' => array(
            'media_youtube' => array(
              'default preset' => 'linked_thumbnail',
              'styles' => array(
                'original' => array(
                  'default preset' => 'video',
                ),
                'thumbnail' => array(
                  'default preset' => 'linked_thumbnail',
                ),
                'square_thumbnail' => array(
                  'default preset' => 'linked_square_thumbnail',
                ),
                'medium' => array(
                  'default preset' => 'linked_medium',
                ),
                'large' => array(
                  'default preset' => 'large_video',
                ),
              ),
              'presets' => array(
                array(
                  'name' => $preset_name,
                  'settings' => $settings,
                  'render callback' => "_jw_player_render_video"
                 )
              );
            ),
          ),
        ),
      );
    }
    
  2. , needs a minor change at lines 114-118 to check if the effect has a defined callback associated with it, if yes then make the callback to render output
             // Loop through and apply each effect.
          foreach ($this->getEffects() as $effect) {
            // What is the effect?
            $effectName = $effect['name'];
            
            if (isset($effect['render callback'])) {
              $render_method = $effect['render callback'];
              if (function_exists($render_method)) {
                $this->setOutput($render_method($this, $effect));
              }
            }
            else {
              if ($effectName && in_array($effectName, $methods)) {
              // Apply the effect with its settings.
              $this->$effectName($effect['settings']);
              }
              else {
                // Ouch. We have an invalid effect. Flag for bug reporting.
                $variables = $this->getVariables();
                $styleName = $variables['style']['name'];
                watchdog('styles', 'Effect %effect_name not found for %style_name display formatter style of the %class_name class.', array('%effect_name' => $effectName, '%style_name' => $styleName, '%class_name' => $this->getClassName()), WATCHDOG_WARNING);
              }
            }
          }
    

    With the tiny changes to code as above, any module that wishes to use existing containers and add presentation presets can do so easily by providing a callback to render output.

✨ Feature request
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Ravi.J

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    Thank you for your contributions to this issue. As Drupal 7 has reached its End of Life and is no longer supported, we are closing this issue. We encourage you to upgrade to a supported version of Drupal.

Production build 0.71.5 2024