Skip to content

Instantly share code, notes, and snippets.

View fago's full-sized avatar

Wolfgang Ziegler fago

View GitHub Profile
@fago
fago / createRulesComponentExample.php
Last active August 29, 2015 14:17
Rules static helpers
<?php
$rule = \Drupal\rules\Rules::expressionManager()
->createRule([
'context_definitions' => [
'user' => [
'type' => 'entity:user',
'label' => 'User',
'description' => 'The user whose mail address to print.',
],
],
@fago
fago / rules-components-config
Created February 8, 2015 14:03
storing rules components
$action = $this->expressionManager->createAction('rules_test_log');
<?php
$config_entity = $this->storage->create([
'id' => 'test_rule',
'expression_id' => 'rules_action',
'configuration' => $action->getConfiguration(),
]);
$config_entity->save();
@fago
fago / php
Created February 8, 2015 14:01
Mapping required and provided context
<?php
$rule = $this->expressionManager->createRule();
// The condition provides a "provided_text" variable.
$rule->addCondition('rules_test_provider');
// The action provides a "concatenated" variable.
$rule->addAction('rules_test_string', [
'context_mapping' => ['text:select' => 'provided_text'],
]);
@fago
fago / gist:77e6ad6744b9620eb9eb
Created February 8, 2015 13:58
create rule with context:
<?php
$rule = $this->expressionManager->createRule([
'context_definitions' => [
'test' => [
'type' => 'string',
'label' => 'Test string',
],
],
]);
@fago
fago / gist:1b6026a5fd6c203f8e19
Created February 5, 2015 20:40
RulesDX for adding actions and conditions
<?php
// Existing PR: https://github.com/fago/rules/pull/134/files
$rule->addCondition('rules_test_string_condition', [
'context_mapping' => ['text:select' => 'node:uid:0:entity:name:0:value'],
]));
]);
// With value object:
$rule->addCondition('rules_test_string_condition', ContextConfig()
->map('text', 'node:uid:0:entity:name:0:value')
PHP Strict standards: Drupal\Core\Plugin\DefaultPluginManager and Drupal\Core\Plugin\CategorizingPluginManagerTrait define the same property ($moduleHandler) in the composition of Drupal\Tests\Core\Plugin\CategorizingPluginManager. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in /home/fago2/projects/d8/drupal/core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php on line 139
@fago
fago / watch.sh
Created March 17, 2014 20:59
Inotify script to trigger a command on file changes, e.g. rsync
#!/bin/bash
# (c) Wolfgang Ziegler // fago
#
# Inotify script to trigger a command on file changes.
#
# The script triggers the command as soon as a file event occurs. Events
# occurring during command execution are aggregated and trigger a single command
# execution only.
#
# Usage example: Trigger rsync for synchronizing file changes.
@fago
fago / gist:5344570
Last active December 15, 2015 23:59
Entity storage
<?php
class DatabaseStorageController implements EntityStorageControllerInterface, ExtensibleStorageInterface {
// Helper class implements the ExtensibleStorageInterface + more needed methods like write().
protected $class = 'ExtensibleDBStorageHelper';
protected function getExtensibleStorageHelper() {
...
}
@fago
fago / gist:5344541
Created April 9, 2013 10:00
storage stuff
class DatabaseStorageController implements EntityStorageControllerInterface, ExtensibleStorageInterface {
protected $class = 'ExtensibleDBStorageHelper';
protected function getExtensibleStorageHelper() {
...
}
function save() {
@fago
fago / gist:4968056
Created February 16, 2013 18:26
$plugin->setContextValue()
/**
* Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::setContextValue().
*/
public function setContextValue($key, $value) {
$context_definition = $this->getContextDefinition($key);
$this->context[$key] = new Context($context_definition);
$this->context[$key]->setValue($value);
if ($this->context[$key]->validate($value)->count() > 0) {
throw new PluginException("The provided value for $key is not valid.");