ajaxyfied image links, fix #3

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-13 20:17:01 +01:00
parent 76565a8b28
commit a0e7fa5f2c
3 changed files with 55 additions and 11 deletions
@@ -8,6 +8,8 @@
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Render\Element;
// function edlptheme_preprocess_input(&$vars){
// dsm($vars, 'vars');
@@ -133,3 +135,28 @@ function edlptheme_preprocess_node__enregistrement__player_cartel(&$vars){
$vars['col_right'] = true;
}
/**
* Prepares variables for image formatter templates.
*
* Default template: image-formatter.html.twig.
*
* @param array $variables
* An associative array containing:
* - item: An ImageItem object.
* - item_attributes: An optional associative array of html attributes to be
* placed in the img tag.
* - image_style: An optional image style.
* - url: An optional \Drupal\Core\Url object.
*/
function edlptheme_preprocess_image_formatter(&$vars){
if(isset($vars['url'])){
$system_path = $vars['url']->getInternalPath();
$vars['link_attributes'] = new Attribute(array(
'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path,
'class' => array('ajax-link')
));
// dpm($vars);
}
}
@@ -0,0 +1,19 @@
{#
/**
* @file
* Theme override to display a formatted image field.
*
* Available variables:
* - image: A collection of image data.
* - image_style: An optional image style.
* - path: An optional array containing the link 'path' and link 'options'.
* - url: An optional URL the image can be linked to.
*
* @see template_preprocess_image_formatter()
*/
#}
{% if url %}
<a href="{{ url }}" {{ link_attributes }}>{{ image }}</a>
{% else %}
{{ image }}
{% endif %}
@@ -10,6 +10,7 @@ dependencies:
- field.field.node.page.field_view_mode
- field.field.node.page.field_visuel
- field.field.node.page.field_workflow_generic
- image.style.large
- node.type.page
module:
- file
@@ -29,7 +30,7 @@ content:
third_party_settings: { }
region: content
field_documents_lies:
weight: 6
weight: 4
label: above
settings:
link: true
@@ -38,32 +39,28 @@ content:
region: content
field_son:
weight: 2
label: above
settings: { }
label: hidden
settings:
use_description_as_link_text: true
third_party_settings: { }
type: file_default
region: content
field_visuel:
weight: 1
label: above
label: hidden
settings:
image_style: ''
image_style: large
image_link: ''
third_party_settings: { }
type: image
region: content
links:
weight: 5
region: content
settings: { }
third_party_settings: { }
production_parent:
weight: 0
region: content
settings: { }
third_party_settings: { }
production_subtree:
weight: 4
weight: 5
region: content
settings: { }
third_party_settings: { }
@@ -72,3 +69,4 @@ hidden:
field_view_mode: true
field_workflow_generic: true
langcode: true
links: true