You are here

function _entity_print_get_css in Entity Print 7

Inject the relevant css for the template.

You can specify CSS files to be included per entity type and bundle in your themes css file. This code uses your current theme which is likely to be the front end theme.

Examples:

entity_print[all] = 'css/all-pdfs.css' entity_print[commerce_order][all] = 'css/orders.css' entity_print[node][article] = 'css/article-pdf.css'

Parameters

string $entity_type: The entity type to add the css for.

object $entity: The entity object.

array $entity_info: The entity info from entity_get_info().

Return value

array An array of stylesheets to be used for this template.

1 call to _entity_print_get_css()
_entity_print_get_generated_html in ./entity_print.module
Generate the HTML for our entity.

File

./entity_print.module, line 196
Print any entity.

Code

function _entity_print_get_css($entity_type, $entity, $entity_info) {

  // Allow other modules to add their own CSS.
  module_invoke_all('entity_print_css', $entity_type, $entity);
  global $theme;
  $theme_path = drupal_get_path('theme', $theme);
  $theme_info = drupal_parse_info_file($theme_path . "/{$theme}.info");

  // Parse out the CSS from the theme info.
  if (isset($theme_info['entity_print'])) {

    // See if we have the special "all" key which is added to every PDF.
    if (isset($theme_info['entity_print']['all'])) {
      entity_print_add_css("{$theme_path}/" . $theme_info['entity_print']['all']);
      unset($theme_info['entity_print']['all']);
    }
    foreach ($theme_info['entity_print'] as $key => $value) {

      // If the entity type doesn't match just skip.
      if ($key !== $entity_type) {
        continue;
      }

      // Parse our css files per entity type and bundle.
      foreach ($value as $css_bundle => $css) {

        // If it's magic key "all" add it otherwise check the bundle.
        if ($css_bundle === 'all' || $entity->{$entity_info['entity keys']['bundle']} === $css_bundle) {
          entity_print_add_css("{$theme_path}/{$css}");
        }
      }
    }
  }

  // Grab all the css files and filter by group so we only have css defined to
  // be used in entity print.
  $entity_print_css = array_filter(drupal_add_css(), function ($a) {
    return $a['group'] === ENTITY_PRINT_CSS_GROUP;
  });
  return $entity_print_css;
}