Skip to content

Instantly share code, notes, and snippets.

Avatar

Kris Vanderwater EclipseGc

View GitHub Profile
View phenaproxima.php
<?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');
View createPhpFileTree.php
<?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);
}
View FilterOEmbedEssence.php
<?php
/**
* @file
* Contains FilterOEmbed.php.
*/
namespace Drupal\oembed\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
View gist:61468a7b0cd01df728eb
<?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'))),
View migrate_export.php
<?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(
View php.php
<?php
$contexts = array(
'node' => new ContextDefinition('entity:node'),
);
drupal_set_message('<pre>' . print_r(\Drupal::service('plugin.manager.condition')->getDefinitionsForContexts($contexts), TRUE) . '</pre>');
View testing.php
<?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.
View gist:618b84fc6f6b7d2f85fd
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.
View HttpStatusCodePageVariant.php
<?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());
View gist:a4e9453d097665f0885a
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'],