You are here

function empty_fields_load_plugin in Empty fields 7.2

Loads a plugin from static cache if available.

Parameters

array $view_mode_settings: The display settings for the view mode.

Return value

emptyfieldHandler The emptyFieldHandler object for the instance's entity.

2 calls to empty_fields_load_plugin()
empty_fields_field_attach_view_alter in ./empty_fields.module
Implements hook_field_attach_view_alter().
empty_fields_field_formatter_settings_summary_alter in ./empty_fields.module
Implements hook_field_formatter_settings_summary_alter().

File

./empty_fields.module, line 35
Contains the implementation for the empty_fields module.

Code

function empty_fields_load_plugin($instance, $view_mode_settings, $view_mode = 'default') {
  static $plugins;
  $field_name = isset($instance['field_name']) ? $instance['field_name'] : 'custom';
  $entity_type = isset($instance['entity_type']) ? $instance['entity_type'] : 'custom';
  $bundle = isset($instance['bundle']) ? $instance['bundle'] : 'custom';
  $key = $entity_type . '-' . $bundle . '-' . $field_name . '-' . $view_mode;
  if (empty($plugins[$key]) && !empty($view_mode_settings['empty_fields_handler']) && class_exists($view_mode_settings['empty_fields_handler'])) {
    $plugin_type = $view_mode_settings['empty_fields_handler'];
    $plugin = new $plugin_type();
    foreach ($plugin
      ->defaults() as $field_id => $default) {
      $field_name = empty_fields_generate_field_name($field_id, $plugin_type);
      $plugin->options[$field_id] = !empty($view_mode_settings[$field_name]) ? $view_mode_settings[$field_name] : $default;
    }

    // Don't cache plugins with missing instance parameters.
    if ($key == 'custom-custom-custom') {
      return $plugin;
    }
    $plugins[$key] = $plugin;
  }
  return isset($plugins[$key]) ? $plugins[$key] : FALSE;
}