Commit 1419359a authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: Added hook_form_alter() and function...

Issue #2249723 by andrei.dincu: Added hook_form_alter() and function xmlsitemap_form_controller() in xmlsitemap.module
parent 40193d46
......@@ -17,6 +17,8 @@ use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
use Drupal\Component\Utility\String;
use Drupal\Core\Render\Element;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityForm;
/**
* The maximum number of links in one sitemap chunk file.
......@@ -1604,14 +1606,112 @@ function xmlsitemap_entity_info_alter(&$entity_info) {
);
}
/**
* Implements hook_preprocess_HOOK() for theme_language_content_settings_table().
*/
function template_preprocess_xmlsitemap_content_settings_table(&$variables) {
// Add a render element representing the bundle language settings table.
$element = $variables['element'];
$header = array(
array(
'data' => $element['#bundle_label'],
'class' => array('bundle'),
),
array(
'data' => t('Configuration'),
'class' => array('operations'),
),
);
$rows = array();
foreach (Element::children($element) as $bundle) {
$rows[$bundle] = array(
'data' => array(
array(
'data' => array(
'#prefix' => '<label>',
'#suffix' => '</label>',
'#markup' => String::checkPlain($element[$bundle]['settings']['#label']),
),
'class' => array('bundle'),
),
array(
'data' => $element[$bundle]['settings'],
'class' => array('operations'),
),
),
'class' => array('bundle-settings'),
);
}
$variables['build'] = array(
'#title' => $element['#title'],
'#header' => $header,
'#rows' => $rows,
'#type' => 'table',
);
}
/**
* Returns HTML for an administration settings table.
*
* @param array $variables
* An associative array containing:
* - build: A render element representing a table of bundle content language
* settings for a particular entity type.
*
* @ingroup themable
*/
function theme_xmlsitemap_content_settings_table($variables) {
return '<h4>' . $variables['build']['#title'] . '</h4>' . drupal_render($variables['build']);
}
/**
* Returns the entity form for the given form.
*
* @param array $form_state
* The form state array holding the entity form.
*
* @return \Drupal\Core\Entity\EntityFormInterface;
* An instance of the entity form interface or FALSE if not an
* entity form.
*/
function xmlsitemap_form_controller(array $form_state) {
return isset($form_state['controller']) && $form_state['controller'] instanceof EntityForm ? $form_state['controller'] : FALSE;
}
/**
* Implements hook_form_alter().
*/
function xmlsitemap_form_alter(array &$form, array &$form_state) {
$form_controller = xmlsitemap_form_controller($form_state);
if (!$form_controller) {
return;
}
$entity = $form_controller ? $form_controller->getEntity() : NULL;
if (!$entity) {
return;
}
$entity_type = $entity->getEntityTypeId();
$bundle = $entity->bundle();
// If this entity/bundle can be included in sitemap alter the form
if (!\Drupal::state()->get('xmlsitemap_entity_' . $entity_type . '_bundle_' . $bundle, 0)) {
return;
}
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, $entity_type, $bundle, $entity->id());
}
/**
* Implements hook_xmlsitemap_index_links().
*/
function xmlsitemap_xmlsitemap_index_links($limit) {
if (\Drupal::state()->get('xmlsitemap_entity_user')) {
$uids = db_query_range("SELECT u.uid FROM {users} u LEFT JOIN {xmlsitemap} x ON x.type = 'user' AND u.uid = x.id WHERE x.id IS NULL AND u.uid > 0 ORDER BY u.uid DESC", 0, $limit)->fetchCol();
xmlsitemap_user_xmlsitemap_process_user_links($uids);
}
}
/**
......@@ -1620,7 +1720,7 @@ function xmlsitemap_xmlsitemap_index_links($limit) {
* @param $uids
* An array of user IDs.
*/
function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) {
/*function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return;
}
......@@ -1629,12 +1729,12 @@ function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
}
}
}*/
/**
* Implements hook_user_presave().
*/
function xmlsitemap_user_presave(UserInterface $account) {
/*function xmlsitemap_user_presave(UserInterface $account) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return;
}
......@@ -1647,48 +1747,48 @@ function xmlsitemap_user_presave(UserInterface $account) {
}
xmlsitemap_link_save($link);
}
}
}*/
/**
* Implements hook_user_insert().
*/
function xmlsitemap_user_insert(UserInterface $account) {
/*function xmlsitemap_user_insert(UserInterface $account) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return;
}
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
}
}*/
/**
* Implements hook_user_update().
*/
function xmlsitemap_user_update(UserInterface $account) {
/*function xmlsitemap_user_update(UserInterface $account) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return;
}
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
}
}*/
/**
* Implements hook_user_delete().
*/
function xmlsitemap_user_delete(UserInterface $account) {
/*function xmlsitemap_user_delete(UserInterface $account) {
xmlsitemap_link_delete('user', $account->id());
}
}*/
/**
* Implements hook_field_extra_fields().
*/
function xmlsitemap_field_extra_fields() {
/*function xmlsitemap_field_extra_fields() {
$extras['user']['user']['form']['xmlsitemap'] = array(
'label' => t('XML sitemap'),
'description' => t('XML sitemap module element'),
'weight' => 30,
);
return $extras;
}
}*/
/**
* Create a sitemap link from a user.
......@@ -1698,7 +1798,7 @@ function xmlsitemap_field_extra_fields() {
* @param $account
* A user object.
*/
function xmlsitemap_user_create_link(UserInterface &$account) {
/*function xmlsitemap_user_create_link(UserInterface &$account) {
if (!isset($account->xmlsitemap)) {
$account->xmlsitemap = array();
if ($account->id() && $link = xmlsitemap_link_load('user', $account->id())) {
......@@ -1733,90 +1833,4 @@ function xmlsitemap_user_create_link(UserInterface &$account) {
$account->xmlsitemap['language'] = !empty($language) ? $language->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED;
return $account->xmlsitemap;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see user_admin_settings()
* @see xmlsitemap_add_link_bundle_settings()
*/
function xmlsitemap_form_user_form_alter(&$form, $form_state) {
// Add the link options.
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, 'user', 'user', \Drupal::currentUser()->id());
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see user_admin_settings()
* @see xmlsitemap_add_link_bundle_settings()
*/
function xmlsitemap_form_user_admin_settings_alter(&$form, $form_state) {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_link_bundle_settings($form, $form_state, 'user', 'user');
//$form['email_title'] += array('#weight' => 10);
$form['email'] += array('#weight' => 10);
}
/**
* Implements hook_preprocess_HOOK() for theme_language_content_settings_table().
*/
function template_preprocess_xmlsitemap_content_settings_table(&$variables) {
// Add a render element representing the bundle language settings table.
$element = $variables['element'];
$header = array(
array(
'data' => $element['#bundle_label'],
'class' => array('bundle'),
),
array(
'data' => t('Configuration'),
'class' => array('operations'),
),
);
$rows = array();
foreach (Element::children($element) as $bundle) {
$rows[$bundle] = array(
'data' => array(
array(
'data' => array(
'#prefix' => '<label>',
'#suffix' => '</label>',
'#markup' => String::checkPlain($element[$bundle]['settings']['#label']),
),
'class' => array('bundle'),
),
array(
'data' => $element[$bundle]['settings'],
'class' => array('operations'),
),
),
'class' => array('bundle-settings'),
);
}
$variables['build'] = array(
'#title' => $element['#title'],
'#header' => $header,
'#rows' => $rows,
'#type' => 'table',
);
}
/**
* Returns HTML for an administration settings table.
*
* @param array $variables
* An associative array containing:
* - build: A render element representing a table of bundle content language
* settings for a particular entity type.
*
* @ingroup themable
*/
function theme_xmlsitemap_content_settings_table($variables) {
return '<h4>' . $variables['build']['#title'] . '</h4>' . drupal_render($variables['build']);
}
}*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment