You are here

views_row_insert.module in Views Row Insert 8

Same filename and directory in other branches
  1. 7 views_row_insert.module

File

views_row_insert.module
View source
<?php

/**
 * @file
 * Contains views_row_insert.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

// Store Views Rows Insert preprocess theme functions in a separate .inc file.
\Drupal::moduleHandler()
  ->loadInclude('views_row_insert', 'inc', 'views_row_insert.theme');

/**
 * Implements hook_help().
 *
 * @inheritdoc
 */
function views_row_insert_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the views_row_insert module.
    case 'help.page.views_row_insert':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Views style plugin to insert custom rows with html data or blocks content into view results.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 *
 * @inheritdoc
 */
function views_row_insert_theme($existing, $type, $theme, $path) {
  return [
    'views_row_insert' => [
      'file' => 'views_row_insert.theme.inc',
    ],
  ];
}

/**
 * Provides list of available system blocks for the form options.
 *
 * @return array
 *   Returns array.
 */
function _views_row_insert_get_blocks() {
  $options = [];
  $definitions = _views_row_insert_get_blocks_definitions();
  foreach ($definitions as $id => $block) {
    if (is_string($block['admin_label'])) {
      $label = $block['admin_label'];
    }
    else {
      $label = $block['admin_label']
        ->render();
    }
    $options[$id] = $label;
  }
  return $options;
}

/**
 * Provides list of available system blocks definitions.
 *
 * @return array
 *   Returns array.
 */
function _views_row_insert_get_blocks_definitions() {
  $blockManager = \Drupal::service('plugin.manager.block');
  $contextRepository = \Drupal::service('context.repository');
  $definitions = $blockManager
    ->getDefinitionsForContexts($contextRepository
    ->getAvailableContexts());
  return $blockManager
    ->getSortedDefinitions($definitions);
}

/**
 * Processing Radios Element using #after_build property.
 *
 * @param array $element
 *   Contains option elements.
 * @param object $form_state
 *   Form object.
 *
 * @return array
 *   Returns array.
 */
function _views_row_insert_process_radios(array $element, $form_state) {
  $options = array_keys($element['#options']);
  foreach ($options as $values) {
    $element[$values]['#attributes']['class'][] = $values;
  }
  return $element;
}

/**
 * Helper function. Provides last key of the array .
 *
 * @param array $new_rows
 *   Array of rows.
 *
 * @return string
 *   Returns key.
 */
function _views_row_insert_last_key(array $new_rows) {
  $keys = array_keys($new_rows);
  return end($keys);
}

Functions

Namesort descending Description
views_row_insert_help Implements hook_help().
views_row_insert_theme Implements hook_theme().
_views_row_insert_get_blocks Provides list of available system blocks for the form options.
_views_row_insert_get_blocks_definitions Provides list of available system blocks definitions.
_views_row_insert_last_key Helper function. Provides last key of the array .
_views_row_insert_process_radios Processing Radios Element using #after_build property.