You are here

public static function Branding::getBannerBranding in Formatter Suite 8

Returns a branding banner.

This function returns a render element that may be added to a page to create a branding banner. The banner includes a container, a logo image, and brief credit text with links and the module's version number.

Return value

array Renders a renderable form array containing branding items.

1 call to Branding::getBannerBranding()
formatter_suite_help in ./formatter_suite.module
Implements hook_help().

File

src/Branding.php, line 172

Class

Branding
Defines functions and constants used for branding.

Namespace

Drupal\formatter_suite

Code

public static function getBannerBranding() {

  //
  // Setup
  // -----
  // Get module information.
  $module = \Drupal::moduleHandler()
    ->getModule('formatter_suite');
  $modulePath = '/' . $module
    ->getPath() . '/';
  $moduleImagesPath = $modulePath . self::MODULE_IMAGES_SUBDIRECTORY . '/';

  // To get the module's version number, we have to parse its YML info file.
  $moduleInfo = \Drupal::service('info_parser')
    ->parse($module
    ->getPathname());
  $moduleVersion = $moduleInfo['version'];

  // Get the path to the module's logo.
  $logoPath = $moduleImagesPath . self::LOGO_FILE_NAME;

  // Define some CSS classes.
  $containerClass = 'formatter_suite-banner-branding';
  $logoClass = 'formatter_suite-branding-logo';

  //
  // Create image HTML and links
  // ---------------------------
  // Create the image HTML.
  $logoImage = '<img class="' . $logoClass . '" alt="' . $module
    ->getName() . '" src="' . $logoPath . '">';

  // Create links.
  $sdscLink = Link::fromTextAndUrl(self::SDSC_TEXT, Url::fromUri(self::SDSC_URL))
    ->toString();
  $ucsdLink = Link::fromTextAndUrl(self::UCSD_TEXT, Url::fromUri(self::UCSD_URL))
    ->toString();
  $nsfLink = Link::fromTextAndUrl(self::NSF_TEXT, Url::fromUri(self::NSF_URL))
    ->toString();

  // Create credit text.
  $credit = t("Developed by the @sdsc at the @ucsd and funded by the @nsf.", [
    '@sdsc' => $sdscLink,
    '@ucsd' => $ucsdLink,
    '@nsf' => $nsfLink,
  ]);

  // Create version text.
  $version = t('Version @version', [
    '@version' => $moduleVersion,
  ]);

  //
  // Return render elements
  // ----------------------
  // Return a render array with a container, the image, credits, and
  // the module version number.
  return [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        $containerClass,
      ],
    ],
    '#attached' => [
      'library' => [
        self::MODULE_BRANDING_LIBRARY,
      ],
    ],
    'logo' => [
      '#markup' => $logoImage,
    ],
    'credits' => [
      '#type' => 'html_tag',
      '#tag' => 'div',
      '#value' => $credit,
    ],
    'version' => [
      '#type' => 'html_tag',
      '#tag' => 'div',
      '#value' => $version,
    ],
  ];
}