Skip to content

Instantly share code, notes, and snippets.

View gargsuchi's full-sized avatar

Suchi Garg gargsuchi

View GitHub Profile
@gargsuchi
gargsuchi / list_text_long_fields.php
Last active January 12, 2021 00:40 — forked from DanLaufer/list_text_long_fields.php
Drupal 8 - PHP Script to list all fields on all content types of a certain type (ex. text_long)
<?php
use Drupal\paragraphs\Entity\Paragraph;
$field_type = 'text_long';
// get node types
$node_types = \Drupal::entityTypeManager()
->getStorage('node_type')
->loadMultiple();
@gargsuchi
gargsuchi / script.php
Created January 12, 2021 00:35 — forked from DanLaufer/script.php
Drupal 8 - Programmatically Update Boolean Fields
<?php
// Single
use Drupal\node\Entity\Node;
$node = Node::load(1537);
$node->set('field_include_pop_up_form',0); // 0 to uncheck, 1 to check
$node->save();
drupal_set_message($node->get('field_include_pop_up_form')->value);
<?php
namespace Drupal\drupalsouth\EventSubscriber;
namespace Drupal\drupalsouth\EventSubscriber;
use Drupal\alexa\AlexaEvent;
use Drupal\views\Views;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\Core\Entity\EntityTypeManager;
<?php
/**
* @file
* Contains lotus.module.
*/
use Drupal\user\Entity\User;
/**
<?php
/**
* @file
* Contains lotus.module.
*/
use Drupal\node\Entity\Node;
/**
function lotus_cron() {
$result = \Drupal::entityQuery("user")
->condition('login', strtotime('-6 months'), '<=')
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage("user");
foreach ($result AS $user) {
$entity = $storage_handler->load($user);
function lotus_cron() {
$result = \Drupal::entityQuery("node")
->condition('created', strtotime('-30 days'), '<=')
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
$entities = $storage_handler->loadMultiple($result);
$storage_handler->delete($entities);
}
<?php
/**
* Controller file for Lotus Drupal 8 module.
* Place this file in src/Controller folder inside the lotus module folder
**/
namespace Drupal\lotus\Controller;
use Drupal\Core\Controller\ControllerBase;