Skip to content
Snippets Groups Projects
Commit c2b443c0 authored by Konstantinos Platis's avatar Konstantinos Platis
Browse files

Initial Commit

parent 6aea3a40
No related branches found
No related tags found
No related merge requests found
Showing with 307 additions and 0 deletions
name: CERN Display Formats
type: module
description: 'Provides a set of display formats designed for the needs of the CERN users.'
package: Web Team Drupal Library
core: '8.x'
dependencies:
- drupal:views
<?php
/**
* Implements hook_requirements().
*
* Checks if the default theme is CERN Theme or a subtheme of the CERN theme.
*/
function cern_display_format_requirements($phase){
$requirements = array();
if($phase == 'install'){
//gets the default theme and checks if it's the CERN Theme.
$config = \Drupal::config('system.theme');
$default = $config->get('default');
if ($default != "cernclean" && $default != "cernuxlibrary"){
$requirements['cernfaqpackage'] = array(
'title' => 'CERN Theme is required',
'description' => 'In order to enable this module you have to have set the CERN Theme as default.',
'severity' => REQUIREMENT_ERROR
);
return $requirements;
}
}
}
<?php
\Drupal::moduleHandler()->loadInclude('cern_display_formats', 'inc', 'display_formats.theme');
use Drupal\views\ViewExecutable;
/**
* Implements hook_theme().
*
* Sets a theme for horizontal boxes
*
*/
function cern_display_formats_theme($existing, $type, $theme, $path) {
return array(
'horizontal_boxes' => array(
'file' => 'display_formats.theme.inc',
),
);
}
//function cern_display_formats_views_pre_render(ViewExecutable $view)
//{
//// $view->displayHandler->option['css_class'] = 'horizontal-boxes';
//// ksm($view);
//// return $view;
//}
name: FAQ Accordion Display Style
type: module
description: 'Provides a View display style that renders FAQS using accordions'
package: Views
core: '8.x'
dependencies:
- drupal:views
\ No newline at end of file
<?php
// Store TARDIS preprocess theme functions in a separate .inc file.
\Drupal::moduleHandler()->loadInclude('cern_faq_accordion_display_style', 'inc', 'faq_accordion.theme');
/**
* Implements hook_theme().
*/
function tardis_theme($existing, $type, $theme, $path) {
return array(
'faq_accordion' => array(
'file' => 'faq_accordion.theme.inc',
),
);
}
\ No newline at end of file
<?php
use Drupal\node\Entity\Node;
/**
* @file
* Theme for FAQ Accordion views.
*/
function template_preprocess_views_view_faq_accordion(&$variables) {
// View options set by user.
$options = $variables['view']->style_plugin->options;
// Build a two-dimension array with years and months.
$faqs = array();
$counter = 0;
foreach ($variables['view']->result as $id => $result) {
$nid = $result->nid;
$node = Node::load($nid);
$question = $node->get('title')->value;
$answer = $node->get('field_answer')->value;
//strip tags in order to sanitize from html tags
$entry = array();
$entry['nid'] = $nid;
$entry['question'] = strip_tags($question);
$entry['answer'] = strip_tags($answer);
$faqs[$counter++] = $entry;
}
$options['faqs'] = $faqs;
//Updates options for twig
$variables['options'] = $options;
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: platico
* Date: 03.08.18
* Time: 09:53
*/
namespace Drupal\cern_faq_accordion_display_style\Plugin\views\style;
use Drupal\core\form\FormStateInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
/**
* Style plugin to render a list of FAQs
*
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "faq_accordion",
* title = @Translation("FAQ Accordion"),
* help = @Translation("Render a list of FAQs presenting them using accordion style"),
* theme = "views_view_faq_accordion",
* display_types = { "normal" }
* )
*/
class FaqAccordion extends StylePluginBase {
/**
* {@inheritdoc}
*/
protected function defineOptions()
{
$options = parent::defineOptions();
$options['path'] = array('default' => 'faq_accordion');
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['first_node_expanded'] = array(
'#type' => 'checkbox',
'#title' => t('First node expanded'),
'#size' => 10,
'#maxlength' => 255,
'#default_value' => 1,
'#required' => TRUE,
'#description' => '<p>' . t('Should the first node be expanded by default?') . '</p>',
);
}
}
\ No newline at end of file
{#
/**
* Default theme implementation for Views to output a TARDIS archive.
*
* Available variables:
* - options: View plugin style options:
* - classes: CSS classes.
* - first_node_expanded: Boolean value on whether the first accordion node should be expanded.
* - path: Link path. Eg.: example.com/TARDIS/2016/03
* - faqs: One-dimension array containing the faq nodes to be rendered
*
* @see template_preprocess_views_view_tardis()
*
* @ingroup themeable
*/
#}
{%
set classes = [
'views-view-faq-accordion',
options.classes
]
%}
<div class="panel-group accordion-cern">
{% for id, values in options.faqs %}
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a
data-toggle="collapse"
class=collapsed'
aria-expanded='false'
href={{ '#collapse'~ values.nid }} >{{ values.question }}
</a>
</h4>
</div>
<div class='panel-collapse collapse'
id={{ 'collapse'~ values.nid }}
aria-expanded='false'
style= 'height: 0px'>
<div class="panel-body">
{{ values.answer }}
</div>
</div>
</div>
{% endfor %}
</div>
\ No newline at end of file
<?php
use Drupal\Core\Template\Attribute;
/**
* @file
*
*/
function template_preprocess_views_view_horizontal_boxes(&$variables) {
$view = $variables['view'];
$rows = $variables['rows'];
$style = $view->style_plugin;
$options = $style->options;
$variables['default_row_class'] = !empty($options['default_row_class']);
foreach ($rows as $id => $row) {
$variables['rows'][$id] = [];
$variables['rows'][$id]['content'] = $row;
$variables['rows'][$id]['attributes'] = new Attribute();
if ($row_class = $view->style_plugin->getRowClass($id)) {
$variables['rows'][$id]['attributes']->addClass($row_class);
}
}
// $variables['css_class'] = 'horizontal-boxes';
}
<?php
namespace Drupal\cern_display_formats\Plugin\views\style;
use Drupal\core\form\FormStateInterface;
use Drupal\views\Plugin\views\style\DefaultStyle;
/**
* Unformatted style plugin to render rows one after another with no
* decorations.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "horizontal_boxes",
* title = @Translation("Horizontal Boxes"),
* help = @Translation("Displays boxes one next to the other. Additionally the boxes can have a carousel effect."),
* theme = "views_view_horizontal_boxes",
* display_types = {"normal"}
* )
*/
class HorizontalBoxes extends DefaultStyle
{
/**
* {@inheritdoc}
*/
protected $usesRowPlugin = true;
//@todo: Implement option for carousel or not.
/**
* Does the style plugin support custom css class for the rows.
*
* @var bool
*/
protected $usesRowClass = true;
protected $usesoptions = true;
protected $renderFields = true;
// public function defineOptions() {
//
// $options = parent::defineOptions();
// ksm($options);
// }
}
\ No newline at end of file
{#<div class="horizontal-boxes">#}
{% if title %}
<h3>{{ title }}</h3>
{% endif %}
{% for row in rows %}
{% set row_classes = [default_row_class ? 'horizontal-boxes-row views-row col-md-4',] %}
{% if loop.first != true and loop.index0 is divisible by(3) %}
</div>
{% endif %}
{% if loop.index0 is divisible by(3) %}
<div class="carousel-cern-item row">
{% endif %}
<div{{ row.attributes.addClass(row_classes) }}>{{ row.content }}</div>
{% if loop.last == true %}
</div>
{% endif %}
{% endfor %}
{#</div>#}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment