Last active
September 5, 2016 12:25
-
-
Save lifofernandez/e0a6bc8baadcc010393dad98714e80f6 to your computer and use it in GitHub Desktop.
snipets utiles para Drupal 7 :)
This file contains hidden or 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
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_url_inbound_alter/7.x | |
function MODULE_url_inbound_alter(&$path, $original_path, $path_language) { | |
// Create the path user/me/edit, which allows a user to edit their account. | |
if (preg_match('|^user/me/edit(/.*)?|', $path, $matches)) { | |
global $user; | |
$path = 'user/' . $user->uid . '/edit' . $matches[1]; # tiene que ser la url original (node/12), no apuntar a otro alias | |
} | |
} |
This file contains hidden or 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 | |
// Tipo de nodo y Taxonomy field | |
// https://www.drupal.org/node/1343708 | |
$query = new EntityFieldQuery(); | |
$query | |
->entityCondition('entity_type', 'node', '=') | |
->propertyCondition('type', 'fondo_patrimonial','=') | |
->propertyCondition('status', 1, '=') | |
//->propertyCondition('created', array($day_start, $day_end), 'BETWEEN'); | |
//->propertyCondition('created', '1294694496', '<'); | |
; | |
$query->fieldCondition('field_area', 'tid', 40, '='); | |
// $query->addTag('debug'); | |
// SQL intercept | |
// http://drupal.stackexchange.com/questions/36542/debug-entityfieldquery | |
/* | |
SELECT field_data_field_area0.entity_type | |
AS entity_type, field_data_field_area0.entity_id | |
AS entity_id, field_data_field_area0.revision_id | |
AS revision_id, field_data_field_area0.bundle | |
AS bundle | |
FROM {field_data_field_area} field_data_field_area0 | |
INNER JOIN {node} node | |
ON node.nid = field_data_field_area0.entity_id | |
WHERE (field_data_field_area0.field_area_tid = '40') | |
AND (field_data_field_area0.deleted = '0') | |
AND (node.type = 'fondo_patrimonial') | |
AND (node.status = '1') | |
AND (field_data_field_area0.entity_type = 'node') | |
*/ | |
$result = $query->execute(); | |
var_dump($result); | |
foreach ($result["node"] as $i => $obj) { | |
$nid = $obj->nid; | |
$fondo = node_load($nid); | |
var_dump($fondo); | |
print $fondo->title.'<br>'; | |
} | |
//https://www.drupal.org/node/2398685 | |
/* | |
$count = db_query( | |
'SELECT COUNT(nid) ' . | |
'FROM {node} AS n ' . | |
'JOIN {field_data_field_if_can_build_layer} AS layer ' . | |
'ON layer.entity_id = n.nid AND layer.entity_type = :node ' . | |
'WHERE n.uid = :uid ' . | |
'AND n.type = :type ' . | |
'AND layer.field_if_can_buy_layer_value = :layer', | |
array( | |
':node' => 'node', | |
':uid' => 12, | |
':type' => 'article', | |
':layer' => 'doing', | |
) | |
)->fetchField(); | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment