Skip to content

Instantly share code, notes, and snippets.

@cyberlex404
Created September 17, 2016 18:21
Show Gist options
  • Save cyberlex404/a5b890577e9985f86390a22c280e122f to your computer and use it in GitHub Desktop.
Save cyberlex404/a5b890577e9985f86390a22c280e122f to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Contains hoover.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Template\Attribute;
use Drupal\node\Entity\NodeType;
use \Drupal\Core\Entity\EntityInterface;
use \Drupal\Core\Entity\Display\EntityViewDisplayInterface;
/**
* Implements hook_help().
*/
function hoover_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the hoover module.
case 'help.page.hoover':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Thomas.ltd Hoover module') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function hoover_theme() {
return array(
'hoover_media_block' => array(
'variables' => array(
'items' => NULL,
//'plugin_id' => NULL,
),
//'file' => 'search.pages.inc',
),
);
}
function template_preprocess_hoover_media_block(&$variables) {
$classes = array(
'swiper-container-media-block',
'swiper-hoover',
);
$variables['#attached']['library'][] = 'hoover/swiper_photos';
$variables['attributes'] = new Attribute($variables['attributes']);
$variables['attributes']->addClass($classes);
}
/**
* Implements hook_entity_extra_field_info().
*/
function hoover_entity_extra_field_info() {
$extra = array();
foreach (NodeType::loadMultiple() as $bundle) {
if($bundle->Id() == 'hoover') {
// producing country
$extra['node'][$bundle->Id()]['display']['producing_country'] = array(
'label' => t('Producing country'),
'description' => t('Producing country value'),
'weight' => 100,
'visible' => TRUE,
);
}
}
return $extra;
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function hoover_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode) {
if ($display->getComponent('producing_country')) {
$build['producing_country'] = [
'#type' => 'markup',
'#markup' => '<span>Германия</span>',
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment