Skip to content

Instantly share code, notes, and snippets.

@HelenaEksler
HelenaEksler / Field formatter view
Created March 1, 2015 08:57
Custom field formatter view for the body field.
/**
* Implements hook_field_formatter_info().
*/
function c4m_message_field_formatter_info() {
return array(
'summary_with_image' => array(
'label' => t('Summary or trimmed with image'),
'field types' => array('text_with_summary'),
)
);
/**
* Overrides \RestfulEntityBaseTaxonomyTerm::checkEntityAccess().
*
* Allow access to create "Tags" resource for privileged users, as
* we can't use entity_access() since entity_metadata_taxonomy_access()
* denies it for a non-admin user.
*/
protected function checkEntityAccess($op, $entity_type, $entity) {
$account = $this->getAccount();
$resource_name = $this->getResourceName();
/**
* Overrides \RestfulEntityBaseTaxonomyTerm::checkPropertyAccess().
*
* Allow user to set the parent term for the unsaved term, even if the user
* doesn't have access to update existing terms, as required by the entity
* metadata wrapper's access check.
*/
protected function checkPropertyAccess($op, $public_field_name, EntityMetadataWrapper $property, EntityMetadataWrapper $wrapper) {
$info = $property->info();
$term = $wrapper->value();
@HelenaEksler
HelenaEksler / FeatureContext.php
Last active August 29, 2015 14:23
Steps for new behat version.
<?php
class FeatureContext extends DrupalContext implements SnippetAcceptingContext {
public function iCheckTheRadioButton($labelText) {
$page = $this->getSession()->getPage();
foreach ($page->findAll('css', 'label') as $label) {
if ( $labelText === $label->getText() ) {
$radioButton = $page->find('css', '#'.$label->getAttribute('for'));
$value = $radioButton->getAttribute('value');
$radioButton->selectOption($value, FALSE);
return;
@HelenaEksler
HelenaEksler / gist:0e632fc94d37e89ff5b6
Created August 6, 2015 09:42
Add .test to user emails.
UPDATE `users` SET `mail` = CONCAT(`mail`, '.test')
@HelenaEksler
HelenaEksler / app.js
Created January 5, 2016 09:14
Add debug into Angular app.
$httpProvider.interceptors.push(function ($q, Auth, localStorageService, $injector) {
return {
'request': function (config) {
var concatWith = /\?/.test(config.url) ? '&' : '?';
if (config.url != 'template/pagination/pagination.html') {
config.url += concatWith + 'XDEBUG_SESSION_START=14394';
}
if (!config.url.match(/login-token/)) {
config.headers = {
$tasks['IMJ_setup_permissions'] = array(
'display_name' => st('Set Blocks'),
'display' => FALSE,
);
------------------------------------------------
/**
@HelenaEksler
HelenaEksler / MigrateBase.php
Last active April 14, 2016 09:30
Function to add translation object to the migrated entity.
<?php
public function addLanguagesToEntityTranslations($entity_type, $entity) {
// Get the basic information about the entity.
$entity_info = entity_get_info($entity_type);
// Get the existing site languages.
$languages = array_keys(language_list());
// Add to the entity translation object. Set the original language to
// the entity's default language.
@HelenaEksler
HelenaEksler / gist:f5530ae235c380316eee
Last active March 6, 2016 09:41
Index Tables with 2 keys
ALTER TABLE `_raw_comb` ADD INDEX(`_itemnume`);
ALTER TABLE `_raw_combh` ADD INDEX(`_itemnume`);
ALTER TABLE `_raw_comb_gal_eng` ADD INDEX(`_itemnume`);
ALTER TABLE `_raw_comb_gal_he` ADD INDEX(`_itemnume`);
@HelenaEksler
HelenaEksler / check-files-exist-from-list.sh
Last active March 25, 2023 15:11
Bash script to check files in list exist in directory
#!/usr/bin/env bash
#Check Files in list from file exist or doesn't exist in directory.
if [ $# -eq 0 ] || [ $# -eq 1 ]
then
echo "You must pass the path to file with the list and the path to directory to check files. \nsh check-file-exist-from-list.sh path/to/file path/to/directory"
exit 1
fi
while read -r file; do