Skip to content

Instantly share code, notes, and snippets.

View EclipseGc's full-sized avatar

Kris Vanderwater EclipseGc

View GitHub Profile
<?php
namespace Drupal\lightning_layout;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
class PanelizerAwareEntityViewDisplay extends EntityViewDisplay {
protected function ensurePanelizerFieldStorage() {
$storage = $this->entityTypeManager()->getStorage('field_storage_config');
<?php
$code = file_get_contents($file);
$tokens = token_get_all($code);
$tree = new \EclipseGc\Ast\Tree;
foreach ($tokens as $id => $token) {
if (is_array($token)) {
$tree->addNode($nodeDictionary->createInstance($token[0], $token[1], $id, $tokens);
}
<?php
/**
* @file
* Contains FilterOEmbed.php.
*/
namespace Drupal\oembed\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
<?php
/**
* Implements hook_requirements().
*/
function git_config_requirements($phase) {
$requirements = array();
$requirements['git-wrapper'] = array(
'title' => t('Git Wrapper'),
'value' => t('!wrapper is required to use the git_config module.', array('!wrapper' => l('Git Wrapper', 'https://github.com/cpliakas/git-wrapper'))),
<?php
$migrate = new Migrator();
$migrate->disabled = FALSE; /* Edit this to true to make a default migrate disabled initially */
$migrate->api_version = 1;
$migrate->machine_name = 'drupal_org_planet_feed';
$migrate->admin_title = 'Drupal.org Planet Feed';
$migrate->source = 'xml';
$migrate->destination = 'node';
$migrate->configuration = array(
<?php
$contexts = array(
'node' => new ContextDefinition('entity:node'),
);
drupal_set_message('<pre>' . print_r(\Drupal::service('plugin.manager.condition')->getDefinitionsForContexts($contexts), TRUE) . '</pre>');
<?php
/**
* Constructs a new context definition object.
*
* @param array $values
* An associative array with the following keys:
* - value: The required data type.
* - required: (optional) Whether the context definition is required.
* - multiple: (optional) Whether the context definition is multivalue.
Existing Rules ContextInterface -> Merge into Drupal\Core\Plugin\Context
Determine if ContextDefinitionInterface is still necessary (instead of DataDefinitionInterface) (hopefully not neccessary).
Form Widget Definitions are not part of Context, Fago will make a separate method for when he needs this at the plugin level.
Allowed values are part of contexts, Kris would prefer a addConstraint() approach to this usage.
Context validation will not happen on setContextValue().
Static methods for plugin context definitions is an implementation detail, Kris doesn't like it but w/e.
Fago wants a ContextException to actually get used & documented.
Fago wants getContext() to return Context objects even if a value has not been set for that context. Kris agrees in principle.
Fago & Kris both support a ContextDefinition Annotation class.
<?php
class HttpStatusCodePageVariant {
public function render() {
$status_code = $this->configuration['status_code'];
$dispatcher = \Drupal::service('event_dispatcher');
$event = new PageManagerViewEvent();
$event->setStatusCode($status_code);
$dispatcher->dispatch(PageManagerEvents::VIEW, $event);
return new Response($event->getContent(), $event->getStatusCode());
diff --git a/src/Plugin/PageVariant/HttpStatusCodePageVariant.php b/src/Plugin/PageVariant/HttpStatusCodePageVariant.php
index c7cd807..64946c1 100644
--- a/src/Plugin/PageVariant/HttpStatusCodePageVariant.php
+++ b/src/Plugin/PageVariant/HttpStatusCodePageVariant.php
@@ -47,6 +47,7 @@ class HttpStatusCodePageVariant extends PageVariantBase {
$options = array(
'404' => $options['404'],
'403' => $options['403'],
+ '301' => $options['301'],
'500' => $options['500'],