This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This Drupal 7 helper function adds a node of bundle 'topic' which has a nat term reference | |
* field 'field_about' which should correspond to the parent term for this node's | |
* sibling 'node'. | |
*/ | |
public function addNATNode($tid, $name) { | |
$parent = db_query('SELECT parent FROM taxonomy_term_hierarchy WHERE tid = :tid', array(':tid' => $tid))->fetchField(); | |
$topic = entity_create('node', array('type' => 'topic')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? php | |
/** | |
* This Drupal 7 helper function can look up if a node exists and is useful | |
* if adding nodes in a postImport() method on a migration or | |
* if needing to avoid duplicates or relate nodes. | |
*/ | |
public function checkNodeExistsByTitle($title) { | |
$query = new EntityFieldQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This helper Drupal 7 function can look up if a term exists and is useful | |
* if adding terms in a postImport() method on a migration or | |
* if needing to avoid duplicates or relate entities to the term. | |
*/ | |
public function checkTermExistsByName($name) { | |
$query = new EntityFieldQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This Drupal 7 helper function will return and echo the count of | |
* taxonomy terms by vocabulary | |
* @param $vid - integer for vocabulary id | |
*/ | |
function GetCountTaxonomyTermsByVocab($vid) { | |
$query = new EntityFieldQuery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Delete all old nodes prior to a certain node id | |
* to prepare DB for migration | |
*/ | |
function DeleteOldNodesByNIDCutoff($nid) { | |
$old_nodes = db_select('node') | |
->fields('node', array('nid')) | |
->condition('node.nid', $nid, '<') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Helper function to fetch the new Drupal 7 ID of a migrated entity | |
* if we know the old id | |
* | |
* @param $old_nid - old nid of biography node from legacy node ref | |
* @return tid of the new term | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Helper class to pass parameters to callback function within preg_replace_callback | |
* to replace absolute D6 urls with D6 aliases | |
*/ | |
class InternalLinksConverter { | |
function replace($matches) { | |
if (isset($this->link_aliases)) { | |
$link_aliases = $this->link_aliases; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Rollback only 'articles' type nodes using the idlist option | |
* This is useful if you can't for some reason rollback the whole migration | |
*/ | |
function migration_update_7001() { | |
// Get the 'migrate' database and query for nodes that should not have been | |
// in our migration class - 52 is the term id for 'articles' | |
$results = Database::getConnection('default', 'migrate') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
*/ | |
function mymodule_form_webform_submission_registration_form_alter(array &$form, FormStateInterface $form_state) { | |
// Show 'Country' as first field. | |
$form['elements']['personal_information']['address']['#country__weight'] = -2; | |
// Show 'State' next, but conditionally. | |
$form['elements']['personal_information']['address']['#state_province__weight'] = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
*/ | |
function mymodule_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) { | |
// @todo come up with a more elegant approach here. | |
// Alter login form and add own custom submit handler. | |
$form['actions']['submit']['#submit'][] = '_mymodule_user_register_form_submit'; | |
} |
OlderNewer