Skip to content

Instantly share code, notes, and snippets.

View rpayanm's full-sized avatar

Rolando rpayanm

View GitHub Profile
<?php
// LOAD
// You can load up the menu tree with MenuLinkTree::load, which will give you an array of menu links to work with. From there it's just a matter of looping through and getting what you need, e.g.
$tree = \Drupal::menuTree()->load('main', new \Drupal\Core\Menu\MenuTreeParameters());
foreach ($tree as $item) {
$title = $item->link->getTitle();
$url_obj = $item->link->getUrlObject();
$has_children = $item->hasChildren;
// etc...

Create tag

git tag -a v1.9.3 -m "v1.9.3"

Push tag

git push origin tag v1.9.3

Delete remote tag

If you want to remove the commit altogether (and every commit that came after that)

git reset --hard adca297de~ //(assuming the commit's hash is adca297de). 
git push origin -f

There are two ways to discover the hook name of a specific component. With the hook name, you can locate its base template file.

First, if you already know the filename of the template, you can infer the hook name from that.

The typical pattern for naming template files is {hook}--{optional context}.html.twig

Hook name dicovery

You can ignore the .html.twig suffix. Which results in {hook}--{optional context}

<?php
namespace Drupal\modal_form_example\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Ajax\ReplaceCommand;
<?php
/**
* Implements hook_module_implements_alter().
*/
function YOURMODULENAME_module_implements_alter(&$implementations, $hook) {
// I want that my hook_form_alter will execute last
// Move our hook_form_alter() implementation to the end of the list.
$my_module = 'MYMODULENAME';
if ($hook == 'form_alter') {
<?php
// Podemos hacerlo en el hook_entity_presave(), ejemplo en un block.
/**
* Implements hook_entity_presave().
*/
function MODULO_NAME_block_content_presave(BlockContent $entity) {
$value_title = $entity->field_container_url->title;
if ($value_title != "") {

The friendly.libraries.yml file will look like this:

friendly-greeting:
  version: 1.0
  license: GPL
  js:
    js/friendly-greeting.js: { }
  dependencies:
    - core/drupalSettings