function node_clone_form_node_admin_content_alter in Node clone 8
Implements hook_form_FORM_ID_alter().
File
- ./
node_clone.module, line 93 - Allow users to make a copy of an item of content (a node) and then edit that copy.
Code
function node_clone_form_node_admin_content_alter(&$form, $form_state, $form_id) {
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// if (variable_get('clone_method', 'prepopulate') == 'prepopulate') {
// $destination = drupal_get_destination();
// }
// else {
// $destination = array();
// }
// The property attribute changes in the $form array depending on the user role.
$property = isset($form['admin']['nodes']['#options']) ? '#options' : '#rows';
if (empty($form['admin']['nodes'][$property])) {
return;
}
// Expose a Clone operation on each node.
foreach ($form['admin']['nodes'][$property] as $nid => &$row) {
$node = \Drupal::entityManager()
->getStorage('node')
->load($nid);
if (node_clone_access_cloning($node)) {
// The structure of this form is different if there is just 1 or more
// than one operation.
if (!isset($row['operations']['data']['#links'])) {
$row['operations']['data']['#links'] = array();
$row['operations']['data']['#attributes']['class'] = array(
'links',
'inline',
);
$row['operations']['data']['#theme'] = 'links__node_operations';
if (isset($row['operations']['data']['#title'])) {
$title = $row['operations']['data']['#title'];
$row['operations']['data']['#links'][$title] = array(
'title' => $title,
'href' => $row['operations']['data']['#href'],
'query' => $row['operations']['data']['#options']['query'],
);
unset($row['operations']['data']['#type']);
}
}
$row['operations']['data']['#links']['clone'] = array(
'title' => t('clone'),
'href' => 'node/' . $nid . '/clone/' . node_clone_get_token($nid),
'query' => $destination,
);
}
}
}