Révision c22e192e
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/ctools/plugins/arguments/entity_id.inc | ||
---|---|---|
3 | 3 |
/** |
4 | 4 |
* @file |
5 | 5 |
* |
6 |
* Plugin to provide an argument handler for all entity ids |
|
6 |
* Plugin to provide an argument handler for all entity ids.
|
|
7 | 7 |
*/ |
8 | 8 |
|
9 | 9 |
/** |
... | ... | |
17 | 17 |
'get child' => 'ctools_argument_entity_id_get_child', |
18 | 18 |
'get children' => 'ctools_argument_entity_id_get_children', |
19 | 19 |
'default' => array( |
20 |
'entity_id' => '' |
|
20 |
'entity_id' => '',
|
|
21 | 21 |
), |
22 | 22 |
'placeholder form' => 'ctools_argument_entity_id_ctools_argument_placeholder', |
23 | 23 |
); |
... | ... | |
41 | 41 |
$plugins[$plugin_id] = $plugin; |
42 | 42 |
} |
43 | 43 |
drupal_alter('ctools_entity_contexts', $plugins); |
44 |
|
|
44 | 45 |
return $plugins; |
45 | 46 |
} |
46 | 47 |
|
... | ... | |
60 | 61 |
return ctools_context_create('entity:' . $entity_type, $arg); |
61 | 62 |
} |
62 | 63 |
|
64 |
// Trim spaces and other garbage. |
|
65 |
$arg = trim($arg); |
|
66 |
|
|
63 | 67 |
if (!is_numeric($arg)) { |
64 | 68 |
$preg_matches = array(); |
65 |
$match = preg_match('/\[id: (\d+)\]/', $arg, $preg_matches);
|
|
69 |
$match = preg_match('/\[id: (\d+)\]/', $arg, $preg_matches); |
|
66 | 70 |
if (!$match) { |
67 | 71 |
$match = preg_match('/^id: (\d+)/', $arg, $preg_matches); |
68 | 72 |
} |
... | ... | |
70 | 74 |
if ($match) { |
71 | 75 |
$id = $preg_matches[1]; |
72 | 76 |
} |
73 |
if (is_numeric($id)) { |
|
77 |
if (isset($id) && is_numeric($id)) {
|
|
74 | 78 |
return ctools_context_create('entity:' . $entity_type, $id); |
75 | 79 |
} |
76 | 80 |
return FALSE; |
77 | 81 |
} |
78 | 82 |
|
79 |
$entity = entity_load($entity_type, array($arg));
|
|
80 |
if (!$entity) {
|
|
83 |
$entities = entity_load($entity_type, array($arg));
|
|
84 |
if (empty($entities)) {
|
|
81 | 85 |
return FALSE; |
82 | 86 |
} |
83 | 87 |
|
84 |
return ctools_context_create('entity:' . $entity_type, $entity[$arg]);
|
|
88 |
return ctools_context_create('entity:' . $entity_type, reset($entities));
|
|
85 | 89 |
} |
86 | 90 |
|
87 | 91 |
function ctools_argument_entity_id_settings_form(&$form, &$form_state, $conf) { |
... | ... | |
119 | 123 |
|
120 | 124 |
$form['settings']['entity_id'] = array( |
121 | 125 |
'#type' => 'value', |
122 |
'#value' => $conf['entity_id'],
|
|
126 |
'#value' => isset($conf['entity_id']) ? $conf['entity_id'] : '',
|
|
123 | 127 |
); |
124 | 128 |
|
125 | 129 |
$form['settings']['entity_type'] = array( |
... | ... | |
132 | 136 |
|
133 | 137 |
function ctools_argument_entity_id_ctools_argument_placeholder($conf) { |
134 | 138 |
$conf = array( |
135 |
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $conf['keyword'])),
|
|
136 |
'#type' => 'textfield',
|
|
137 |
'#maxlength' => 512,
|
|
139 |
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $conf['keyword'])), |
|
140 |
'#type' => 'textfield', |
|
141 |
'#maxlength' => 512, |
|
138 | 142 |
'#autocomplete_path' => 'ctools/autocomplete/' . $conf['keyword'], |
139 |
'#weight' => -10,
|
|
143 |
'#weight' => -10, |
|
140 | 144 |
); |
145 |
|
|
141 | 146 |
return $conf; |
142 | 147 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules