Revision 82e80b81
Added by Andreas Kohlbecker almost 2 years ago
modules/cdm_dataportal/ext_links/ext_links.admin.inc | ||
---|---|---|
22 | 22 |
$form['link_templates'][$id]['link'] = array('#markup' => check_plain($link_template->link)); |
23 | 23 |
$form['link_templates'][$id]['glue'] = array('#markup' => check_plain($link_template->glue)); |
24 | 24 |
$form['link_templates'][$id]['category'] = array('#markup' => check_plain($link_template->category)); |
25 |
$form['link_templates'][$id]['configure'] = array('#type' => 'link', '#title' => t('configure'), '#href' => 'admin/config/content/link_templates/' . $id); |
|
26 |
$form['link_templates'][$id]['disable'] = array('#type' => 'link', '#title' => t('disable'), '#href' => 'admin/config/content/link_templates/' . $id . '/disable', '#access' => !$form['link_templates'][$id]['#is_fallback']); |
|
25 |
$form['link_templates'][$id]['configure'] = array('#type' => 'link', '#title' => t('configure'), '#href' => 'admin/config/cdm_dataportal/ext_links/' . $link_template->id); |
|
26 |
$form['link_templates'][$id]['status'] = array('#type' => 'link', |
|
27 |
'#title' => $link_template->status == 1 ? t('disable') : t('enable'), |
|
28 |
'#href' => 'admin/config/cdm_dataportal/ext_links/' . $link_template->id . '/status/' . ($link_template->status == 1 ? '0' : '1')); |
|
27 | 29 |
$form['link_templates'][$id]['weight'] = array( |
28 | 30 |
'#type' => 'weight', |
29 | 31 |
'#title' => t('Weight for @title', array('@title' => $link_template->name)), |
30 | 32 |
'#title_display' => 'invisible', |
31 | 33 |
'#default_value' => $link_template->weight, |
32 | 34 |
); |
35 |
$form['link_templates'][$id]['#attributes']['class'] = []; |
|
36 |
if($link_template->status != 1){ |
|
37 |
$form['link_templates'][$id]['#attributes']['class'][] = 'disabled'; |
|
38 |
} |
|
33 | 39 |
} |
34 | 40 |
$form['actions'] = array('#type' => 'actions'); |
35 | 41 |
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save changes')); |
... | ... | |
53 | 59 |
drupal_set_message(t('The text format ordering has been saved.')); |
54 | 60 |
} |
55 | 61 |
|
62 |
/** |
|
63 |
* Page callback: Displays external link template add/edit form. |
|
64 |
* |
|
65 |
* @param object|null $link_template |
|
66 |
* (optional) An object representing an external link template, with the following properties: |
|
67 |
* - title: The link title |
|
68 |
* - link: The link url template. |
|
69 |
* - glue: The string to concatenate name parts in the URL query string. |
|
70 |
* - status: (optional) An integer indicating whether the ext link is |
|
71 |
* enabled (1) or not (0). Defaults to 1. |
|
72 |
* - weight: (optional) The weight of the external link, which controls its |
|
73 |
* placement in external link block. If omitted, the weight is set to 0. |
|
74 |
* Defaults to NULL. |
|
75 |
* |
|
76 |
* @return |
|
77 |
* A form array. |
|
78 |
* |
|
79 |
* @see filter_menu() |
|
80 |
*/ |
|
81 |
function ext_links_admin_link_template_page($link_template = NULL) { |
|
82 |
if (!isset($link_template->name)) { |
|
83 |
drupal_set_title(t('Add external link')); |
|
84 |
$link_template = (object) array( |
|
85 |
'title' => NULL, |
|
86 |
'link' => 'https://', |
|
87 |
'glue' => '', |
|
88 |
'weight' => 0, |
|
89 |
'status' => 1 |
|
90 |
); |
|
91 |
} |
|
92 |
return drupal_get_form('ext_links_admin_link_template_form', $link_template); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
/** |
|
97 |
* Form constructor for the External Link add/edit form. |
|
98 |
* |
|
99 |
* @param $link_template |
|
100 |
* A link template object having the properties: |
|
101 |
* - id: A machine-readable name representing the ID of the external link. |
|
102 |
* If this corresponds to an existing external link, that format will be |
|
103 |
* updated; otherwise, a new external link will be created. |
|
104 |
* - title: The link title |
|
105 |
* - link: The link url template. |
|
106 |
* - glue: The string to concatenate name parts in the URL query string. |
|
107 |
* - status: (optional) An integer indicating whether the ext link is |
|
108 |
* enabled (1) or not (0). Defaults to 1. |
|
109 |
* - weight: (optional) The weight of the external link, which controls its |
|
110 |
* placement in external link block. If omitted, the weight is set to 0. |
|
111 |
* Defaults to NULL. |
|
112 |
* |
|
113 |
* @see ext_links_admin_link_template_form_validate() |
|
114 |
* @see ext_links_admin_link_template_form_submit() |
|
115 |
* @ingroup forms |
|
116 |
*/ |
|
117 |
function ext_links_admin_link_template_form($form, &$form_state, $link_template) { |
|
118 |
$is_fallback = ($link_template->format == filter_fallback_format()); |
|
119 |
|
|
120 |
$form['#format'] = $link_template; |
|
121 |
$form['#tree'] = TRUE; |
|
122 |
// $form['#attached']['js'][] = drupal_get_path('module', 'filter') . '/filter.admin.js'; |
|
123 |
// $form['#attached']['css'][] = drupal_get_path('module', 'filter') . '/filter.css'; |
|
124 |
|
|
125 |
$form['id'] = array( |
|
126 |
'#type' => 'machine_name', |
|
127 |
'#required' => TRUE, |
|
128 |
'#default_value' => $link_template->id, |
|
129 |
'#maxlength' => 255, |
|
130 |
'#machine_name' => array( |
|
131 |
'exists' => 'ext_link_exists', |
|
132 |
), |
|
133 |
'#disabled' => !empty($link_template->id), |
|
134 |
); |
|
135 |
$form['title'] = array( |
|
136 |
'#type' => 'textfield', |
|
137 |
'#title' => t('Title'), |
|
138 |
'#default_value' => $link_template->title, |
|
139 |
'#description' => t('The text of the link that will be displayed.'), |
|
140 |
'#required' => TRUE, |
|
141 |
); |
|
142 |
$form['link'] = array( |
|
143 |
'#type' => 'textfield', |
|
144 |
'#title' => t('Link'), |
|
145 |
'#description' => t('The URL of the link to the external resource or service. |
|
146 |
The species name parts will be appended to this string.<p>E.g. |
|
147 |
<code>https://external-service.test/images?q=</code> will result in |
|
148 |
<code>https://external-service.test/images?q=Bellis+perennis</code> when the glue string is set to "+"</p>'), |
|
149 |
'#default_value' => $link_template->link, |
|
150 |
'#required' => TRUE, |
|
151 |
); |
|
152 |
$form['glue'] = array( |
|
153 |
'#type' => 'textfield', |
|
154 |
'#title' => t('Glue'), |
|
155 |
'#description' => t('The string used to concatenate genus and species name parts in the query string.'), |
|
156 |
'#default_value' => $link_template->glue, |
|
157 |
'#required' => false, |
|
158 |
); |
|
159 |
$form['status'] = array( |
|
160 |
'#type' => 'checkbox', |
|
161 |
'#title' => t('Enabled'), |
|
162 |
'#default_value' => $link_template->status |
|
163 |
); |
|
164 |
$form['weight'] = array( |
|
165 |
'#type' => 'weight', |
|
166 |
'#title' => t('Weight'), |
|
167 |
'#default_value' => $link_template->weight, |
|
168 |
'#delta' => 10, |
|
169 |
); |
|
170 |
$form['actions'] = array('#type' => 'actions'); |
|
171 |
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
172 |
|
|
173 |
return $form; |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Form submission handler for ext_links_admin_link_template_form(). |
|
178 |
*/ |
|
179 |
function ext_links_admin_link_template_form_submit($form, &$form_state) { |
|
180 |
// Remove unnecessary values. |
|
181 |
form_state_values_clean($form_state); |
|
182 |
|
|
183 |
// Add the submitted form values to the text link_template, and save it. |
|
184 |
$link_template = $form['#link_template']; |
|
185 |
foreach ($form_state['values'] as $key => $value) { |
|
186 |
$link_template->$key = $value; |
|
187 |
} |
|
188 |
$status = ext_links_save($link_template); |
|
189 |
|
|
190 |
switch ($status) { |
|
191 |
case SAVED_NEW: |
|
192 |
drupal_set_message(t('Added external link %link_template.', array('%link_template' => $link_template->id))); |
|
193 |
break; |
|
194 |
|
|
195 |
case SAVED_UPDATED: |
|
196 |
drupal_set_message(t('The text link_template %link_template has been updated.', array('%link_template' => $link_template->id))); |
|
197 |
break; |
|
198 |
} |
|
199 |
} |
|
56 | 200 |
|
57 | 201 |
/** |
58 | 202 |
* Returns HTML for the text format administration overview form. |
... | ... | |
64 | 208 |
* @ingroup themeable |
65 | 209 |
*/ |
66 | 210 |
function theme_ext_links_admin_overview($variables) { |
211 |
|
|
212 |
drupal_add_css(drupal_get_path('module', 'ext_links'). '/ext-links.admin.css'); |
|
213 |
|
|
67 | 214 |
$form = $variables['form']; |
68 | 215 |
|
69 | 216 |
$rows = array(); |
70 | 217 |
foreach (element_children($form['link_templates']) as $id) { |
218 |
$row_class_attributes = $form['link_templates'][$id]['#attributes']['class']; |
|
219 |
$row_class_attributes[] = 'draggable'; |
|
71 | 220 |
$form['link_templates'][$id]['weight']['#attributes']['class'] = array('text-format-order-weight'); |
72 | 221 |
$rows[] = array( |
73 | 222 |
'data' => array( |
... | ... | |
77 | 226 |
drupal_render($form['link_templates'][$id]['category']), |
78 | 227 |
drupal_render($form['link_templates'][$id]['weight']), |
79 | 228 |
drupal_render($form['link_templates'][$id]['configure']), |
80 |
drupal_render($form['link_templates'][$id]['disable']),
|
|
229 |
drupal_render($form['link_templates'][$id]['status']),
|
|
81 | 230 |
), |
82 |
'class' => array('draggable'),
|
|
231 |
'class' => $row_class_attributes,
|
|
83 | 232 |
); |
84 | 233 |
} |
85 | 234 |
$header = array(t('Title'), t('Link'), t('Glue'), t('Weight'), t('Category'), array('data' => t('Operations'), 'colspan' => 2)); |
Also available in: Unified diff
ref #9659 admin overview improved and edit form ready