Skip to content

Instantly share code, notes, and snippets.

View jcicero518's full-sized avatar

Jeff Cicero jcicero518

View GitHub Profile
(function ($, Drupal) {
'use strict';
Drupal.behaviors.reCaptchaFix = {
attach: function (context, settings) {
if (context == document) {
var intervalID = window.setInterval(setAccesibilityLabel, 50);
function setAccesibilityLabel() {
var textAreaCheck = document.getElementsByClassName('g-recaptcha-response');
if (textAreaCheck.length > 0) {
@jcicero518
jcicero518 / guzzleclient.php
Created December 9, 2022 21:36
Drupal GuzzleHttp XML
<?php
$client = \Drupal::httpClient();
// Sending application/x-www-form-urlencoded POST requests requires
// that you specify the POST fields as an array in the form_params request options.
$req = $client->request('POST', $url, [
'form_params' => [
'action' => urlencode($action),
'username' => urlencode($username),
$ brew info gpatch | grep "gpatch:" gpatch: stable 2.7.5 (bottled)
<?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 / 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 / content.html.twig
Created April 26, 2022 19:03
Drupal Link URLs
{# Assuming link field has a machine name of field_call_to_action_button #}
{% set cta_link_url = '' %}
{% set cta_has_link = 'no' %}
{% if content.field_call_to_action_button['#items'] %}
{# @var route_object - instance of Drupal\Core\Url #}
{% set route_object = content.field_call_to_action_button['#items'].0.url %}
{% set link_title = content.field_call_to_action_button['#items'].title %}
{% if route_object.external %}
@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();