Skip to content
Snippets Groups Projects
Commit 26da40b7 authored by Liam Morland's avatar Liam Morland
Browse files

Coding standards

parent 560ba639
No related branches found
No related tags found
1 merge request!10Coding standards
<?php <?php
/**
* @file
*/
/**
*
*/
function addAttachLibraryFunction(\Twig_Environment &$env, $config) { function addAttachLibraryFunction(\Twig_Environment &$env, $config) {
$env->addFunction(new \Twig_SimpleFunction('attach_library', function ($string) { $env->addFunction(new \Twig_SimpleFunction('attach_library', function ($string) {
return; return;
......
<?php <?php
/** /**
* @file * @file
* Add "create_attribute" function for Pattern Lab. * Add "create_attribute" function for Pattern Lab.
*/ */
/**
*
*/
function addCreateAttributeFunction(\Twig_Environment &$env, $config) { function addCreateAttributeFunction(\Twig_Environment &$env, $config) {
$function = new Twig_SimpleFunction( $function = new Twig_SimpleFunction(
'create_attribute', 'create_attribute',
function ($attributes = []) { function ($attributes = []) {
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
if (!is_array($value)) { if (!is_array($value)) {
$value = array($value); $value = [$value];
} }
print ' ' . $key . '="' . join(' ', $value) . '"'; print ' ' . $key . '="' . join(' ', $value) . '"';
} }
}, },
array('is_safe' => array('html')) ['is_safe' => ['html']]
); );
$env->addFunction($function); $env->addFunction($function);
} }
<?php <?php
/**
* @file
*/
/**
*
*/
function addLinkFunction(\Twig_Environment &$env, $config) { function addLinkFunction(\Twig_Environment &$env, $config) {
$env->addFunction(new Twig_SimpleFunction( $env->addFunction(new Twig_SimpleFunction(
'link', 'link',
...@@ -6,10 +14,11 @@ function addLinkFunction(\Twig_Environment &$env, $config) { ...@@ -6,10 +14,11 @@ function addLinkFunction(\Twig_Environment &$env, $config) {
if (isset($attributes) && isset($attributes['class'])) { if (isset($attributes) && isset($attributes['class'])) {
$classes = join(' ', $attributes['class']); $classes = join(' ', $attributes['class']);
return '<a href="' . $url . '" class="' . $classes . '">' . $title . '</a>'; return '<a href="' . $url . '" class="' . $classes . '">' . $title . '</a>';
} else { }
else {
return '<a href="' . $url . '">' . $title . '</a>'; return '<a href="' . $url . '">' . $title . '</a>';
} }
}, },
array('is_safe' => array('html')) ['is_safe' => ['html']]
)); ));
} }
<?php <?php
/**
* @file
*/
/**
*
*/
function addPathFunction(\Twig_Environment &$env, $config) { function addPathFunction(\Twig_Environment &$env, $config) {
$env->addFunction(new \Twig_SimpleFunction('path', function ($string) { $env->addFunction(new \Twig_SimpleFunction('path', function ($string) {
if ($string === '<front>') { if ($string === '<front>') {
return '/'; return '/';
} else { }
else {
return $string; return $string;
} }
})); }));
......
<?php <?php
/**
* @file
*/
/**
*
*/
function addUrlFunction(\Twig_Environment &$env, $config) { function addUrlFunction(\Twig_Environment &$env, $config) {
// https://www.drupal.org/node/2486991 // https://www.drupal.org/node/2486991
$env->addFunction(new \Twig_SimpleFunction('url', function ($string) { $env->addFunction(new \Twig_SimpleFunction('url', function ($string) {
......
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