Skip to content

Instantly share code, notes, and snippets.

@jerbob92
jerbob92 / MyModuleTaskWorkerEntityUpdate.php
Last active November 28, 2016 18:17
QueueWorker in Drupal 8
<?php
/**
* @file
* Contains \Drupal\mymodule\Plugin\QueueWorker\MyModuleTaskWorkerEntityUpdate.
*/
namespace Drupal\mymodule\Plugin\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
@jerbob92
jerbob92 / MyModuleMenuLinkDerivative.php
Created October 27, 2015 13:29
Drupal 8 Derative Menu Link Example
<?php
/**
* @file
* Contains \Drupal\mymodule\Plugin\Derivative\MyModuleMenuLinkDerivative.
*/
namespace Drupal\mymodule\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
@jerbob92
jerbob92 / MyModuleMenuLink.php
Created October 27, 2015 13:31
Drupal 8 Derative Advanced Menu Link Example
@jerbob92
jerbob92 / ImageRenderExampleBlock.php
Created October 28, 2015 13:20
Render image into a block Drupal 8 Example
<?php
/**
* @file
* Contains Drupal\mymodule\Plugin\Block\ImageRenderExampleBlock.
*/
namespace Drupal\mymodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;
@jerbob92
jerbob92 / ImageRenderExampleBlockByURI.php
Created October 28, 2015 13:21
Render image into a block Drupal 8 Example by URI
<?php
/**
* @file
* Contains Drupal\mymodule\Plugin\Block\ImageRenderExampleBlockByURI.
*/
namespace Drupal\mymodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;
@jerbob92
jerbob92 / ImageRenderExampleBlockResponsive.php
Created October 28, 2015 13:22
Render responsive image into a block Drupal 8 Example
<?php
/**
* @file
* Contains Drupal\mymodule\Plugin\Block\ImageRenderExampleBlockResponsive.
*/
namespace Drupal\mymodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;
@jerbob92
jerbob92 / validate.php
Created August 27, 2016 11:00
Validate Entity D8
<?php
$errors = array();
$validate = $entity->validate();
$violations = $validate->getIterator();
foreach ($violations as $violation) {
$constraint = get_class($violation->getConstraint());
$type = $constraint;
$msg = $violation->getMessageTemplate();
if ($constraint == 'Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraint') {
@jerbob92
jerbob92 / lookup-page-example.php
Created March 23, 2017 14:12
Creating default pages in Drupal 8
<?php
use Drupal\node\Entity\Node;
$current_language = \Drupal::languageManager()->getCurrentLanguage();
$default_pages = \Drupal::state()->get('my_module.default_pages', array());
$node_id = (isset($default_pages['front_' . $current_language->getId()]) ? $default_pages['front_' . $current_language->getId()] : NULL);
if (!$node_id) {
return NULL;
}
@jerbob92
jerbob92 / php_mdb.rst
Created August 15, 2017 11:41 — forked from amirkdv/php_mdb.rst
How to handle MS Access MDB files in Linux with PHP5 PDO and ODBC

To be able to use PHP5 PDO with MS Access mdb files the following is required (the same applies for the PHP4 style of using odbc_X except for the obviously PDO specific requirements):

PHP ODBC module

In Linux this is achieved by intalling the php5-odbc package:

@jerbob92
jerbob92 / drupal-SA-002-check.sh
Created March 28, 2018 19:04
Check whether Drupal 7.58 and 8.5.1 are released
#!/bin/sh
url="https://ftp.drupal.org/files/projects/drupal-7.58.zip";
if curl --output /dev/null --silent --head --fail "$url"; then
echo "URL exists: $url";
else
echo "URL does not exist: $url";
fi;
url="https://ftp.drupal.org/files/projects/drupal-8.5.1.zip";