Drupal 8 Html::load()

kenneth
/** @var string $html */
$html = <<<HTML
         <a href="/" title="home">Home</a>
HTML;
/** @var DOMElement $element */
foreach (Drupal\Component\Utility\Html::load($html)->getElementsByTagName('a') as $element) {
    $href = $element->getAttribute('href');
    $title = $element->getAttribute('title');
    echo "{$title} is redirecting to {$href}" . PHP_EOL;
}

 

Drupal 8: Re-run update N hook

kenneth
UPDATE key_value SET value='i:8000;' WHERE collection = 'system.schema' AND name = 'module_name';

Or

\Drupal::keyValue('system.schema')->set('module_name', (int) 8000);

Even

drush ev "\Drupal::keyValue('system.schema')->set('module_name', (int) 8000)";

drush eval "drupal_set_installed_schema_version("module_name", 8000)"

 

Pantheon - Drupal 8 + Upstream Updates

kenneth
# Official Pantheon documentation reference here: https://pantheon.io/docs/core-updates/#overwrite-core
 git pull -Xtheirs git://github.com/pantheon-systems/drops-8.git master

 

Drupal 8 Load EntityViewDisplay instance

kenneth

use Drupal\Core\Entity\Entity\EntityViewDisplay;

// Define values to load entity
$entity_type = 'node';
$bundle = 'article';
$view_mode = 'teaser';

// Setup entity view display ID
$entity_id = sprintf('%s.%s.%s', $entity_type, $bundle, $view_mode);

// Load entity view display object using entity id.
$entityViewDisplay = EntityViewDisplay::load($entity_id);

 

Subscribe to