Skip to content

Instantly share code, notes, and snippets.

@djevans
djevans / VariablePager.php
Created May 15, 2017 20:51
Views pager plugin with the option to have a different number of items on the first page.
<?php
namespace Drupal\views_first_page\Plugin\views\Pager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\pager\Full;
/**
* @ViewsPager(
* id = "variable_pager",
@djevans
djevans / orx_saved_searches.module
Created April 25, 2017 13:36
Cron hook in progress
<?php
/**
* Implements hook_cron().
*/
function orx_saved_searches_cron() {
$query = <<<EOF
SELECT id, view_path FROM {saved_search}
WHERE (last_executed IS NULL OR last_queued < last_executed)
AND last_queued + notification_interval <= :request_time
@djevans
djevans / Link.php
Last active June 3, 2016 09:44
Rendering Link elements in Drupal 8.
@djevans
djevans / entity.php
Last active March 22, 2016 16:36
Setting multi-valued reference fields programmatically in Drupal 8.
<?php
use Drupal\node\Entity\Node;
// node 1 has 'field_ref', which is a multi-valued field currently referencing nodes 2 and 3.
$node = Node::load(1);
$node->field_ref[] = 4;
$node->save(); // 'field_ref' now contains [2,3,4].