Skip to content

Instantly share code, notes, and snippets.

View jcicero518's full-sized avatar

Jeff Cicero jcicero518

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Web Components</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
margin: 0 auto;
@jcicero518
jcicero518 / nicaragua.module
Created July 10, 2023 22:08 — forked from dinarcon/nicaragua.module
Conditional fields in Paragraphs using the Javascript States API for Drupal 8
/**
* @file
* Example code from http://agaric.com/blogs/conditional-fields-paragraphs-using-javascript-states-api-drupal-8.
*/
/**
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
*
* Example of conditional fields in paragraphs for Drupal 8.
*/
@jcicero518
jcicero518 / NewBlock.php
Created December 7, 2022 22:38 — forked from drubb/NewBlock.php
Drupal 9 block using node context. Works for node pages, node revision pages and node previews.
<?php
namespace Drupal\title_block\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a block rendering the title of the current node.
*
* @Block(
@jcicero518
jcicero518 / drupal-entity-query-or-and-reference.php
Created April 20, 2022 21:42 — forked from mecmartini/drupal-entity-query-or-and-reference.php
Drupal 8 entity query with or condition and entity reference field
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
$orGroup = \Drupal::entityQuery('node')->orConditionGroup()
->condition('type', 'page');
->condition('type', 'article')
->condition('type', 'landing');
$result = \Drupal::entityQuery('node')
->status(1)
->condition($orGroup)
<?php
use Drupal\node\NodeInterface;
/**
* Implements hook_ENTITY_TYPE_view().
*/
function mymodule_node_view(array &$build, NodeInterface $node, $display, $view_mode) {
if ($node->getType() === 'post') {
$build['#cache']['max-age'] = 0;
<?php
/**
* Removing traces of the test_marco_socialfood_workflow module after merging.
*/
function hook_update_N() {
$schema_store = \Drupal::keyValue('system.schema');
$schema_store->delete('module_name');
\Drupal::database()->delete('key_value')
@jcicero518
jcicero518 / drupal-and-react-library.php
Created April 20, 2022 21:37 — forked from mecmartini/drupal-and-react-library.php
Drupal and React - Create library
<?php
/**
* Implements hook_library_info_build().
*/
function drupal_and_react_library_info_build() {
# Load current module path.
$module = \Drupal::moduleHandler()->getModule('drupal_and_react');
$module_path = $module->getPath();
@jcicero518
jcicero518 / drupal-test-csv.php
Created April 20, 2022 21:34 — forked from mecmartini/drupal-test-csv.php
Drupal - Test CSV
<?php
namespace Drupal\Tests\tablefield\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Simple test to ensure that a field can be created.
*
* @group tablefield
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$id = $items->getEntity()->id();
# Generate a wrapper to use as dom root to attach the React component.
$field_name = $this->fieldDefinition->getItemDefinition()->getFieldDefinition()->getName();
$wrapper_id = 'drupal-and-react-app-' . $field_name .'-'. $id;
@jcicero518
jcicero518 / remove_view_duplicates.includes.php
Created March 30, 2022 18:14 — forked from mattschaff/remove_view_duplicates.includes.php
Drupal 8: Remove duplicate records in view
<?php
/**
* Implements hook_preprocess_views_view
*/
function my_module_preprocess_views_view(&$vars){
// Only use unique IDs for view.
// Use this code for views with Better Exposed Filters.
if ($vars['view']->id() === 'view_name_bef') {
$rows = [];