Skip to content

Instantly share code, notes, and snippets.

View sdboyer's full-sized avatar

sam boyer sdboyer

View GitHub Profile
@sdboyer
sdboyer / z.php
Last active October 8, 2015 00:07
<?php
function Z($step) {
$cmb = function($next) use ($step) {
// the following lambda makes it a Z combinator instead of Y. But w/out lazy eval, it has to be here
return $step(function() use ($next) {
return call_user_func_array($next($next), func_get_args());
});
// A lazy lang can do a true Y combinator, which would look something like this instead
@sdboyer
sdboyer / ConfigDrivenFactory.php
Last active December 15, 2015 14:29
quick POC of a config-sensitive plugin factory, and the config and plugin interfaces it entails. even if we don't do this, i think it's worth noting that i think we'd be much better served in general if we tried to do less constructor injection with plugins - setter injection is typically fine. the only drawback to it is that it could be set aga…
<?php
/**
* @file
* Contains Drupal\Core\Plugin\Factory\ConfigDrivenFactory.
*/
namespace Drupal\Core\Plugin\Factory;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Plugin\Factory\DefaultFactory;
@sdboyer
sdboyer / config.inc.php
Created April 1, 2013 13:24
new prefix-agnostic config entity loader
<?php
/**
* Loads the correct type of ConfigEntity from a full configuration object name.
*
* ConfigEntity expects that the id passed to entity_load() will not include the
* config prefix used by the entity type being loaded. This is unhelpful for
* calling code that has the fully prefixed configuration object name and can
* not reliably know the specific type of ConfigEntity to load.
*
* This function figures out which type of entity the configuration object
@sdboyer
sdboyer / block.routing.yml
Created April 3, 2013 02:29
block routes
block_address_standalone:
pattern: '/block-address/standalone/{block_config}/{route}'
defaults:
_controller: 'block_controller:respond'
requirements:
_access_addressed_block: 'TRUE'
block_address_embedded:
pattern: '/block-address/embedded/{display}'
defaults:
@sdboyer
sdboyer / Block.php
Last active December 15, 2015 19:29
still not quite done, but a better example
<?php
/**
* @file
* Contains \Drupal\block\Plugin\Core\Entity\Block.
*/
namespace Drupal\block\Plugin\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
@sdboyer
sdboyer / BlockBase.php
Last active December 16, 2015 08:19
block title getting
<?php
class BlockBase {
/**
* {@inheritdoc}
*/
final public function getTitle() {
// Override titles should supersede native title logic.
if (isset($this->configuration['label'])) {
// @todo tokenization?
}
block_address_standalone:
pattern: '/block-address/standalone/{block_id}/{route}'
defaults:
_controller: 'block_controller:respond'
requirements:
_access_addressed_block: 'TRUE'
block_address_embedded:
pattern: '/block-address/embedded/{display}/{block_id}'
defaults:
@sdboyer
sdboyer / gist:5606040
Created May 18, 2013 23:07
rough assessment of the blocks we have that break data encapsulation
- BookNavigationBlock
- menu_get_object() called from build, in search of a node
- book_get_books() called, if in "all pages" mode, to search out book/current page associations
- lots of menu_tree_output(), etc., called, which relies on current path info
- ActiveTopicsBlock and NewTopicsBlock
- not breaking data encapsulation, but calls drupal_render_cache_by_query()
- LanguageBlock
- menu_is_front_page()/current_path()
@sdboyer
sdboyer / AssetGroupingInterface.php
Created May 23, 2013 20:35
AssetGroupingInterface
<?php
/**
* @file
* Contains Drupal\Core\Asset\AssetGroupingInterface.
*/
namespace Drupal\Core\Asset;
/**
* Interface defining a service that organizes sets of assets into groups.
@sdboyer
sdboyer / theme.php
Last active December 17, 2015 18:09
notes on what to do with page preprocessing
<?php
function template_preprocess_page(&$variables) {
$language_interface = language(LANGUAGE_TYPE_INTERFACE); // DC
$site_config = config('system.site'); // DC
// Move some variables to the top level for themer convenience and template cleanliness.
$variables['show_messages'] = $variables['page']['#show_messages']; // Bad
foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
if (!isset($variables['page'][$region_key])) {