Skip to content

Instantly share code, notes, and snippets.

View oksana-c's full-sized avatar

Oksana Cyrus oksana-c

View GitHub Profile
@oksana-c
oksana-c / hook_inline_entity_form_table_fields_alter.php
Last active October 9, 2018 19:14
Display a field from a custom entity in the Inline Entity Form widget table.
<?php
/**
* Implements hook_inline_entity_form_table_fields_alter().
*
* Displays a field from a custom entity in the Inline Entity Form windget table.
*/
function MODULENAME_inline_entity_form_table_fields_alter(&$fields, $context) {
// Display Entity field in a column within Inline Entity Form widget.
if ($context['parent_bundle'] == 'content_type_parent_to_ief' && $context['field_name'] == 'entity_reference_field_name') {
// Unset original IEF label if needed.
@oksana-c
oksana-c / ExampleAttachTermsProgrammatically.php
Created October 4, 2018 17:15 — forked from dreambubbler/ExampleAttachTermsProgrammatically.php
Drupal 8: Attach terms to entity programmatically
<?php
use Drupal\node\Entity\Node;
/**
* Before attaching a term(s) to a term reference field,
* Must know:
* - field_example_name: the full name of the term reference field
* - tid: the term ID(s) to attach
*
* Keep in mind that this example uses Node::load()
@oksana-c
oksana-c / gen-d8-salt.sh
Created September 20, 2018 17:59 — forked from pfaocle/gen-d8-salt.sh
Generate Drupal 8 hash salt
drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"
@oksana-c
oksana-c / MODULENAME.install.php
Created August 29, 2018 21:56 — forked from daggerhart/MODULENAME.install.php
Drupal 8 file field to media entities simple migration. Does not move files in filesystem, just creates new media entities.
<?php
/**
* Create media entities from existing file fields.
*
* @link https://chromatichq.com/blog/migrating-drupal-file-fields-media-entities-without-migrate-module
*/
function MODULENAME_update_8001() {
// Nodes types that will get media migrated.
$node_types = ['article','event','page','session','sponsor'];
// Map old file fields => new media fields.
@oksana-c
oksana-c / any.php
Created August 20, 2018 17:24 — forked from robdecker/any.php
Drupal 7: Link l() function with attributes.
l(
t('<span></span>Link Title'),
'link_path',
array(
'attributes' => array(
'class' => array('menu-link'),
'id' =>'faq-page',
),
'html' => TRUE,
),
@oksana-c
oksana-c / gist:087a59fb3853cdab30d3dc6033edcc37
Created August 9, 2018 22:07 — forked from grasmash/gist:9746671
Behat FeatureContext.php for Drupal
<?php
use Drupal\DrupalExtension\Context\DrupalContext,
Drupal\DrupalExtension\Event\EntityEvent,
Drupal\Component\Utility\Random;
use Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step,
Behat\Behat\Context\Step\Given,
Behat\Gherkin\Node\PyStringNode,
@oksana-c
oksana-c / inheritance.php
Created July 11, 2018 10:55 — forked from Integralist/inheritance.php
Refreshing my memory on PHP inheritance and general OOP
<?php
// Configure error messages
ini_set('display_errors',1);
error_reporting(E_ALL);
class Adult {
/*
We set the visibility of these properties to 'protected' so they are accessible within the Child class.
We prefix private and protected properties/methods with an underscore, so (at a glance) while scanning a long file we can instantly recognise the visibility.
@oksana-c
oksana-c / automated_db_pull.sh
Created December 2, 2017 17:28
Automated Drupal DB Pull from the server with Drush sql-dump
#!/usr/bin/env bash
# This script can be run from any location.
# - sh automated_dbpull.sh
# SSH to the server using SSH key.
ssh -tt -i ~/.ssh/id_rsa YOURUSERNAME@SERVER << EOF
cd /var/www/sites/SITEDIRECTORY/www;
drush sql-dump --result-file=../build/DBNAMEOFCHOICE.sql --gzip --structure-tables-key=cache,cache_*,history,search_*,sessions,watchdog;
exit;
@oksana-c
oksana-c / .eslintrc
Created July 19, 2017 12:14 — forked from jibran/.eslintrc
Sample eslint file for Drupal 7
{
"env": {
"browser": true
},
"globals": {
"Drupal": true,
"jQuery": true,
"tinyMCE": true
},
"rules": {
@oksana-c
oksana-c / dc_emw.php
Created July 11, 2017 23:15 — forked from BBGuy/dc_emw.php
Working with Drupal commerce entities using entity_metadata_wrapper. Just a bunch of exampled copied from the web or added by me. will keep adding over time. now more then just commerce entities
<?php
// Basics
// Get a value.
$value = $wrapper->field_x->value();
// If the field is a reference field you will get the field object
// To get the wrapper back use:
$wrapper_b = $wrapper->field_ref;
// To set a value.