Issue #1938920 by akalata, Jon Pugh, joelpittet, shanethehat, lauriii, martin107, nicholasruunu: Convert node_search_admin theme tables to table #type
parent
d0374825f3
commit
d07e48a61b
|
@ -138,10 +138,6 @@ function node_theme() {
|
|||
'node' => array(
|
||||
'render element' => 'elements',
|
||||
),
|
||||
'node_search_admin' => array(
|
||||
'render element' => 'form',
|
||||
'function' => 'theme_node_search_admin',
|
||||
),
|
||||
'node_add_list' => array(
|
||||
'variables' => array('content' => NULL),
|
||||
'file' => 'node.pages.inc',
|
||||
|
@ -729,40 +725,6 @@ function node_user_predelete($account) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the content ranking part of the search settings admin page.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - form: A render element representing the form.
|
||||
*
|
||||
* @see node_search_admin()
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_node_search_admin($variables) {
|
||||
$form = $variables['form'];
|
||||
|
||||
$output = drupal_render($form['info']);
|
||||
|
||||
$header = array(t('Factor'), t('Influence'));
|
||||
foreach (Element::children($form['factors']) as $key) {
|
||||
$row = array();
|
||||
$row[] = $form['factors'][$key]['#title'];
|
||||
$form['factors'][$key]['#title_display'] = 'invisible';
|
||||
$row[] = drupal_render($form['factors'][$key]);
|
||||
$rows[] = $row;
|
||||
}
|
||||
$table = array(
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
);
|
||||
$output .= drupal_render($table);
|
||||
|
||||
$output .= drupal_render_children($form);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Title callback: Displays the node's title.
|
||||
*
|
||||
|
|
|
@ -597,19 +597,27 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
'#title' => t('Content ranking'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['content_ranking']['#theme'] = 'node_search_admin';
|
||||
$form['content_ranking']['info'] = array(
|
||||
'#markup' => '<p><em>' . $this->t('Influence is a numeric multiplier used in ordering search results. A higher number means the corresponding factor has more influence on search results; zero means the factor is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em></p>'
|
||||
);
|
||||
// Prepare table.
|
||||
$header = [$this->t('Factor'), $this->t('Influence')];
|
||||
$form['content_ranking']['rankings'] = array(
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
);
|
||||
|
||||
// Note: reversed to reflect that higher number = higher ranking.
|
||||
$range = range(0, 10);
|
||||
$options = array_combine($range, $range);
|
||||
foreach ($this->getRankings() as $var => $values) {
|
||||
$form['content_ranking']['factors']["rankings_$var"] = array(
|
||||
'#title' => $values['title'],
|
||||
$form['content_ranking']['rankings'][$var]['name'] = array(
|
||||
'#markup' => $values['title'],
|
||||
);
|
||||
$form['content_ranking']['rankings'][$var]['value'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#attributes' => ['aria-label' => $this->t("Influence of '@title'", ['@title' => $values['title']])],
|
||||
'#default_value' => isset($this->configuration['rankings'][$var]) ? $this->configuration['rankings'][$var] : 0,
|
||||
);
|
||||
}
|
||||
|
@ -621,8 +629,8 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
foreach ($this->getRankings() as $var => $values) {
|
||||
if (!$form_state->isValueEmpty("rankings_$var")) {
|
||||
$this->configuration['rankings'][$var] = $form_state->getValue("rankings_$var");
|
||||
if (!$form_state->isValueEmpty(['rankings', $var, 'value'])) {
|
||||
$this->configuration['rankings'][$var] = $form_state->getValue(['rankings', $var, 'value']);
|
||||
}
|
||||
else {
|
||||
unset($this->configuration['rankings'][$var]);
|
||||
|
|
|
@ -114,17 +114,17 @@ class SearchRankingTest extends SearchTestBase {
|
|||
|
||||
// Check that all rankings are visible and set to 0.
|
||||
foreach ($node_ranks as $node_rank) {
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-rankings-' . $node_rank . '"]//option[@value="0"]'), 'Select list to prioritize ' . $node_rank . ' for node ranks is visible and set to 0.');
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-rankings-' . $node_rank . '-value"]//option[@value="0"]'), 'Select list to prioritize ' . $node_rank . ' for node ranks is visible and set to 0.');
|
||||
}
|
||||
|
||||
// Test each of the possible rankings.
|
||||
$edit = array();
|
||||
foreach ($node_ranks as $node_rank) {
|
||||
// Enable the ranking we are testing.
|
||||
$edit['rankings_' . $node_rank] = 10;
|
||||
$edit['rankings[' . $node_rank . '][value]'] = 10;
|
||||
$this->drupalPostForm('admin/config/search/pages/manage/node_search', $edit, t('Save search page'));
|
||||
$this->drupalGet('admin/config/search/pages/manage/node_search');
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-rankings-' . $node_rank . '"]//option[@value="10"]'), 'Select list to prioritize ' . $node_rank . ' for node ranks is visible and set to 10.');
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-rankings-' . $node_rank . '-value"]//option[@value="10"]'), 'Select list to prioritize ' . $node_rank . ' for node ranks is visible and set to 10.');
|
||||
|
||||
// Reload the plugin to get the up-to-date values.
|
||||
$this->nodeSearch = entity_load('search_page', 'node_search');
|
||||
|
@ -134,7 +134,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
$this->assertEqual($set[0]['node']->id(), $nodes[$node_rank][1]->id(), 'Search ranking "' . $node_rank . '" order.');
|
||||
|
||||
// Clear this ranking for the next test.
|
||||
$edit['rankings_' . $node_rank] = 0;
|
||||
$edit['rankings[' . $node_rank . '][value]'] = 0;
|
||||
}
|
||||
|
||||
// Save the final node_rank change then check that all rankings are visible
|
||||
|
@ -142,7 +142,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
$this->drupalPostForm('admin/config/search/pages/manage/node_search', $edit, t('Save search page'));
|
||||
$this->drupalGet('admin/config/search/pages/manage/node_search');
|
||||
foreach ($node_ranks as $node_rank) {
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-rankings-' . $node_rank . '"]//option[@value="0"]'), 'Select list to prioritize ' . $node_rank . ' for node ranks is visible and set to 0.');
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-rankings-' . $node_rank . '-value"]//option[@value="0"]'), 'Select list to prioritize ' . $node_rank . ' for node ranks is visible and set to 0.');
|
||||
}
|
||||
|
||||
// Try with sticky, then promoted. This is a test for issue
|
||||
|
|
Loading…
Reference in New Issue