Révision e4c061ad
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/ctools/plugins/arguments/entity_id.inc | ||
---|---|---|
16 | 16 |
'context' => 'ctools_argument_entity_id_context', |
17 | 17 |
'get child' => 'ctools_argument_entity_id_get_child', |
18 | 18 |
'get children' => 'ctools_argument_entity_id_get_children', |
19 |
'default' => array( |
|
20 |
'entity_id' => '' |
|
21 |
), |
|
22 |
'placeholder form' => 'ctools_argument_entity_id_ctools_argument_placeholder', |
|
19 | 23 |
); |
20 | 24 |
|
21 | 25 |
function ctools_argument_entity_id_get_child($plugin, $parent, $child) { |
... | ... | |
57 | 61 |
} |
58 | 62 |
|
59 | 63 |
if (!is_numeric($arg)) { |
64 |
$preg_matches = array(); |
|
65 |
$match = preg_match('/\[id: (\d+)\]/', $arg, $preg_matches); |
|
66 |
if (!$match) { |
|
67 |
$match = preg_match('/^id: (\d+)/', $arg, $preg_matches); |
|
68 |
} |
|
69 |
|
|
70 |
if ($match) { |
|
71 |
$id = $preg_matches[1]; |
|
72 |
} |
|
73 |
if (is_numeric($id)) { |
|
74 |
return ctools_context_create('entity:' . $entity_type, $id); |
|
75 |
} |
|
60 | 76 |
return FALSE; |
61 | 77 |
} |
62 | 78 |
|
... | ... | |
68 | 84 |
return ctools_context_create('entity:' . $entity_type, $entity[$arg]); |
69 | 85 |
} |
70 | 86 |
|
87 |
function ctools_argument_entity_id_settings_form(&$form, &$form_state, $conf) { |
|
88 |
$plugin = &$form_state['plugin']; |
|
89 |
|
|
90 |
$form['settings']['entity'] = array( |
|
91 |
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $plugin['keyword'])), |
|
92 |
'#type' => 'textfield', |
|
93 |
'#maxlength' => 512, |
|
94 |
'#autocomplete_path' => 'ctools/autocomplete/' . $plugin['keyword'], |
|
95 |
'#weight' => -10, |
|
96 |
); |
|
97 |
|
|
98 |
if (!empty($conf['entity_id'])) { |
|
99 |
$info = entity_load($plugin['keyword'], array($conf['entity_id'])); |
|
100 |
$info = $info[$conf['entity_id']]; |
|
101 |
if ($info) { |
|
102 |
$entity = entity_get_info($plugin['keyword']); |
|
103 |
$uri = entity_uri($plugin['keyword'], $info); |
|
104 |
if (is_array($uri) && $entity['entity keys']['label']) { |
|
105 |
$link = l(t("'%title' [%type id %id]", array('%title' => $info->{$entity['entity keys']['label']}, '%type' => $plugin['keyword'], '%id' => $conf['entity_id'])), $uri['path'], array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE)); |
|
106 |
} |
|
107 |
elseif (is_array($uri)) { |
|
108 |
$link = l(t("[%type id %id]", array('%type' => $plugin['keyword'], '%id' => $conf['entity_id'])), $uri['path'], array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE)); |
|
109 |
} |
|
110 |
elseif ($entity['entity keys']['label']) { |
|
111 |
$link = l(t("'%title' [%type id %id]", array('%title' => $info->{$entity['entity keys']['label']}, '%type' => $plugin['keyword'], '%id' => $conf['entity_id'])), file_create_url($uri), array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE)); |
|
112 |
} |
|
113 |
else { |
|
114 |
$link = t("[%type id %id]", array('%type' => $plugin['keyword'], '%id' => $conf['entity_id'])); |
|
115 |
} |
|
116 |
$form['settings']['entity']['#description'] = t('Currently set to !link', array('!link' => $link)); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
$form['settings']['entity_id'] = array( |
|
121 |
'#type' => 'value', |
|
122 |
'#value' => $conf['entity_id'], |
|
123 |
); |
|
124 |
|
|
125 |
$form['settings']['entity_type'] = array( |
|
126 |
'#type' => 'value', |
|
127 |
'#value' => $plugin['keyword'], |
|
128 |
); |
|
129 |
|
|
130 |
return $form; |
|
131 |
} |
|
132 |
|
|
133 |
function ctools_argument_entity_id_ctools_argument_placeholder($conf) { |
|
134 |
$conf = array( |
|
135 |
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $conf['keyword'])), |
|
136 |
'#type' => 'textfield', |
|
137 |
'#maxlength' => 512, |
|
138 |
'#autocomplete_path' => 'ctools/autocomplete/' . $conf['keyword'], |
|
139 |
'#weight' => -10, |
|
140 |
); |
|
141 |
return $conf; |
|
142 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules