Skip to content

Instantly share code, notes, and snippets.

@init90
init90 / scratch.txt
Created May 6, 2019 15:56
Drupal 7, create metatags programality.
// The type of entity being edited.
$entity_type = 'node';
// The ID of the entity being changed.
$entity_id = 42;
// The revision ID for this entity, leave as NULL to ignore revisioning.
$revision_id = NULL;
// The language code for this entity.
$langcode = LANGUAGE_NONE;
// Load the existing values, will return an empty array if anything found.
$metatags = metatag_metatags_load($entity_type, $entity_id, $revision_id);
@init90
init90 / editor.js
Created February 7, 2019 13:41
JS, run some action when all fonts loaded.
document.fonts.ready.then(function() {
canvas.renderAll();
});
@init90
init90 / gist:9a91adcad4fe868ec114f97d5b0baed0
Last active February 6, 2019 22:13
Drupal 7, commerce. Get all order ids from anonymous users which have cart status.
$status_ids = array_keys(commerce_order_statuses(array('cart' => TRUE)));
$cart_order_ids = db_query('SELECT order_id FROM {commerce_order} WHERE uid = 0 AND status IN (:status_ids)', array(
':status_ids' => $status_ids,
))->fetchCol();
@init90
init90 / scratch.txt
Last active December 3, 2018 11:01
Drupal 7, update multisite with drush.
// Backup databases.
drush @sites sql-dump --result-file --gzip
// Run update.
drush @sites updb
// Clear cache.
drush @sites cc all
@init90
init90 / skg_generate_product_types.module
Created November 13, 2018 16:38
Drupal 7, set permissions programality.
$perms = array(
// Node.
"create $bundle_name content",
"edit own $bundle_name content",
"edit any $bundle_name content",
"delete own $bundle_name content",
"delete any $bundle_name content",
// Commerce.
"create commerce_product entities of bundle $bundle_name",
@init90
init90 / skg_generate_product_types.module
Created November 13, 2018 15:26
Drupal 7, modify views filter settings programality.
$views_name = 'newest_products';
$display_name = 'page';
$filter_name = 'type';
// Add content type to allowed list in filter settings.
$view = views_get_view($views_name, TRUE);
$views_filters = $view->display[$display_name]->display_options['filters'];
$views_filters[$filter_name]['value'][$bundle_name] = $bundle_name;
$view->save();
/**
* Set product output across panel.
*
* @param string $bundle_name
* Product bundle name.
*/
function sgpt_add_new_type_to_panel_settings($bundle_name) {
$task_name = 'node_view';
$variant_name = 'node_view__product';
$node_view_tasks = page_manager_get_task($task_name);
$entity_type = 'entity_type_name';
$field_name = 'field_name';
$bundle = 'bundle_name';
// Delete field instance.
if ($instance = field_info_instance($entity_type, $field_name, $bundle)) {
field_delete_instance($instance, TRUE);
field_purge_batch(1);
}
@init90
init90 / scratch.txt
Last active October 23, 2018 15:15
Docksel, install "oauth" php extension.
fin bash
sudo apt-get install install libpcre3-dev
sudo pecl install oauth
sudo docker-php-ext-enable oauth
exit
fin restart
@init90
init90 / gist:1125f84887e130ac1fbdae859b47dbb1
Last active September 24, 2018 10:04
Drupal 8, get first field collection item.
if ($entity->get('FIELD_COLLECTION_FIELD')->count() > 0) {
$settings = $entity->get('FIELD_COLLECTION_FIELD')->first()->getFieldCollectionItem();
}