Skip to content

Instantly share code, notes, and snippets.

View steveoliver's full-sized avatar

Steve Oliver steveoliver

View GitHub Profile
@steveoliver
steveoliver / user-login-block-better.html.twig
Created November 7, 2012 19:21
User login block (better) extends User login block.
{# modules/user/templates/user-login-block.html.twig #}
{% block "login-link" %}
<div class="user-login-block-link">
{{ link }}
</div>
{% endblock %}
@steveoliver
steveoliver / gist:4081603
Created November 15, 2012 21:59
Drupal 8 Twig Debug Comments
<!-- BEGIN 'comment_wrapper__node_article' THEME MARKUP -->
<!-- FROM core/themes/stark/templates/node/node--1.html.twig -->
<!-- FILE NAME SUGGESTIONS:
x node--1.html.twig
* node--article.html.twig
* node.html.twig
-->
<article id="node-1">
<h2>Title</h2>
// ...
@steveoliver
steveoliver / Partial response handling notes
Created January 31, 2013 20:27
Notes on sdboyers comments about partial response handling
// controller arguments
$arguments = $this->resolver->getArguments($request, $controller);
// call controller
// i.e. from menu_execute_active_handler
//
$response = call_user_func_array($controller, $arguments);
// if controller wasn't smart enough to return a complete response...
@steveoliver
steveoliver / gist:4750736
Created February 10, 2013 19:31
Drupal 8 Best Practices in Preprocess functions and Twig templates
<h3 id="bestpractices">Best Practices in Preprocess Functions and Twig Templates</h3>
In order to minimize wasteful calls to unneeded resources and make Drupal 8 themeing as performant as possible, please follow these best practices:
<ol>
<li>Always call <code>t()</code> within templates; never call t() in preprocess.</li>
<li>Always return render arrays instead of ever calling <code>theme()</code> within a preprocess function.</li>
</ol>
Discussing this on our call today, Fabianx pointed out one possibility. Take our example of image field instances within a node template:
To get at the src (or any other) attribute of the first image field instance, one would print:
<code>{{ content.field_image.attributes.src }}</code>
1. The field <code>attributes</code> have not yet been prepared in the context of the parent node template.
2. <code>TwigTemplate::getAttribute()</code> determines the attribute does not exist and then calls a function, tentatively named <code>render_structure()</code>, which returns the variables as would be available in the child template.
3. Then .src and other variables are available.
@steveoliver
steveoliver / gist:5879504
Created June 27, 2013 19:18
Discussion between steveoliver and Fabianx on the topic of Twig variable drillability.
***: Buffer Playback...
Fabianx: [15:17:27] steveoliver: pong
Fabianx: [15:17:50] steveoliver: Can you pass me the link to drill able again (sorry during moving, not much time left  )
***: Playback Complete.
steveoliver: 2008450
Druplicon: https://drupal.org/node/2008450 => Provide for a drillable variable structure in Twig templates [#2008450] => Drupal core, theme system, major, needs work, 12 comments, 10 IRC mentions
steveoliver: Fabianx: ^^
Fabianx: steveoliver: So implementation is:
Fabianx: ( proof-of-concept)
Fabianx: * Add a new parameter to render and theme.
@steveoliver
steveoliver / theme.inc
Created October 16, 2013 03:50
theme.inc::template_preprocess_html checking visibilitiy of regions using has_render_content().
// Add information about the number of sidebars.
if (has_render_content($variables['page'], 'sidebar_first') && has_render_content($variables['page'], 'sidebar_second')) {
$variables['attributes']['class'][] = 'two-sidebars';
}
elseif (has_render_content($variables['page'], 'sidebar_first')) {
$variables['attributes']['class'][] = 'one-sidebar';
$variables['attributes']['class'][] = 'sidebar-first';
}
elseif (has_render_content($variables['page'], 'sidebar_second')) {
$variables['attributes']['class'][] = 'one-sidebar';
@steveoliver
steveoliver / common.inc
Created October 16, 2013 03:51
has_render_content() function
/**
* Checks that a render array has content that can be rendered.
*
* @param $element
* The element to check.
*
* @param $offset
* The key of the child to check.
*
* @return bool
@steveoliver
steveoliver / gist:7469874
Created November 14, 2013 16:33
Next buttons first
diff --git a/includes/wizard.inc b/includes/wizard.inc
index 6f5d794..a3227b5 100644
--- a/includes/wizard.inc
+++ b/includes/wizard.inc
@@ -291,13 +291,25 @@ function ctools_wizard_wrapper($form, &$form_state) {
$button_attributes = array('class' => array('ctools-use-ajax'));
}
+ // If there is a next form, place the next button.
+ if (isset($form_state['next']) || !empty($form_info['free trail'])) {
@steveoliver
steveoliver / README.md
Last active March 10, 2016 19:00
Adding an SSL domain to platform.sh with GoDaddy certificate and intermediate chain bundle