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
To quickly start with a new custom module is can be convenient to copy an exisiting. But you then need a quick way to rename files, folders and string within files. | |
##Rename files and folders | |
Look for files that contain STRINGTOLOOKFOR in name: | |
`find . -name "STRINGTOLOOKFOR*" -exec rename -v 's/STRINGTOLOOKFOR/STRINGTOREPLACEWITH/i' {} \;` | |
For example: | |
`find . -name "bcca_tools*" -exec rename -v 's/bcca_tools/project_tools/i' {} \;` |
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
use Drupal\node\Entity\Node; | |
function _svv_tools_set_author() { | |
$user = user_load_by_name('test'); | |
$query = \Drupal::entityQuery('node'); | |
$nids = $query->execute(); | |
dd($nids); | |
foreach ($nids as $nid) { | |
$node = Node::load($nid); | |
$node->uid->value = $user->id(); |
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
$result = db_query("SELECT * from system where name = 'best_practice_db'"); | |
debug($result->fetchObject()); |
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
// Enable flexslider modules. | |
$modules = array( | |
'flexslider', | |
'flexslider_fields', | |
'flexslider_views', | |
'flexslider_views_slideshow', | |
); | |
module_enable($modules); |
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
$contexts = variable_get('context_status', array()); | |
$disable = array('homepage','sitewide','dae_search_empty','webmasters','no_twitter','workbench_moderate_all','go-to-market','newsroom_events','communities_audence_link','digital_champion_newsroom','grand_coalition_pledge','workbench_moderate_all'); | |
foreach($disable as $item) { | |
$contexts[$item] = TRUE; | |
} | |
variable_set('context_status', $contexts); |
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
/** | |
* Deletes obsolete contexts. | |
*/ | |
function mymodule_update_7132() { | |
$disable = array( | |
'single_telecom_market_news', | |
'oi24u_community', | |
'dae_side_blocks', | |
); |
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
$field_name = 'field_name'; | |
$field = field_read_field($field_name); | |
$field['locked'] = 0; // 0: unlock; 1: lock. | |
field_update_field($field); |
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
$form['interval'] = [ | |
'#type' => 'textfield', | |
'#title' => $this->t('Reactivation interval'), | |
'#description' => $this->t(''), | |
'#maxlength' => 64, | |
'#size' => 64, | |
'#default_value' => $config->get('interval'), | |
'#suffix' => "<div class='description' id='human-interval'></div>", | |
'#description'=> $this->('Period after which account must be reactivated. Must be entered in days.'), | |
'#attached' => [ |
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
# drop db, create db, import db | |
mysql -uroot -proot -D -e "DROP DATABASE mydatabase";mysql -uroot -proot -D -e "CREATE DATABASE mydatabase";mysql -uroot -proot mydatabase < mydatabase.sql | |
# drop db, create db, unzip db, import db | |
mysql -uroot -proot -D -e "DROP DATABASE mydatabase";mysql -uroot -proot -D -e "CREATE DATABASE mydatabase";gunzip mydatabase.sql.gz | mysql -uroot -proot mydatabase < mydatabase.sql |
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
MacBook-Pro:drupal-vm jim$ vagrant reload --provision | |
==> drupalvm: [vagrant-hostsupdater] Removing hosts | |
Password: | |
==> drupalvm: Attempting graceful shutdown of VM... | |
==> drupalvm: Checking if box 'geerlingguy/ubuntu1604' is up to date... | |
==> drupalvm: Clearing any previously set forwarded ports... | |
==> drupalvm: Clearing any previously set network interfaces... | |
==> drupalvm: Preparing network interfaces based on configuration... | |
drupalvm: Adapter 1: nat | |
drupalvm: Adapter 2: hostonly |