Skip to content

Instantly share code, notes, and snippets.

@netlooker
Last active December 5, 2015 22:04
Show Gist options
  • Save netlooker/0fb92aba011bcb43601c to your computer and use it in GitHub Desktop.
Save netlooker/0fb92aba011bcb43601c to your computer and use it in GitHub Desktop.
Project Property Helper Class
It is better to use one storage for all of hardcoded values like tid, vid, nid etc.
class ProjectProps {
$DYNAMIC_PROPERTY
const PROPERTY_NAME = 'static value';
function setDynamicProperty() {
$self::DYNAMIC_PROPERTY = dynamic_function();
}
}
IN .module file put this on top - after that
// Loading helper classes
module_load_include('php', 'project_core', 'class/ProjectProps');
$x = ProjectProps::PROPERTY_NAME;
Multiple references fileds query from one entity
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'bundle_name')
->propertyCondition('status', NODE_PUBLISHED)
->fieldCondition('field_app_name', 'value', $value, '=')
->fieldCondition('field_app_ref_1', 'target_id', $value_ref, '=')
->fieldCondition('field_app_ref_2', 'target_id', $array(list of IDs), '=')
->fieldOrderBy('field_app_name', 'value', 'ASC')
$results = $query->execute();
// Example how to use EntityMetaData Wrapper
function get_node_field_values($node_object){
$node_wrapper = entity_metadata_wrapper('node', $node_object);
return array(
'nid' => $node_wrapper->nid->value(),
'title' => $node_wrapper->title->value(),
'field_1' => $node_wrapper->field_app_name_1->value(),
);
}
// Examples of how to use #states
$form['field_name']['#states'] = array(
'visible' => array(
'#field-selector_1' => array('value' => $value),
'#field-selector_2' => array('!value' => '_none'),
),
'required' => array(
'#field-selector_1' => array('value' => $value),
'#field-selector_2' => array('!value' => '_none'),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment