Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -13,9 +13,11 @@ mode: default
content:
author:
weight: -2
region: content
comment_body:
type: text_textarea
weight: 11
region: content
settings:
rows: 5
placeholder: ''
@ -23,6 +25,7 @@ content:
subject:
type: string_textfield
weight: 10
region: content
settings:
size: 60
placeholder: ''

View file

@ -17,6 +17,7 @@ content:
body:
type: text_textarea_with_summary
weight: 27
region: content
settings:
rows: 9
summary_rows: 3
@ -25,11 +26,13 @@ content:
comment_forum:
type: comment_default
weight: 20
region: content
settings: { }
third_party_settings: { }
created:
type: datetime_timestamp
weight: 10
region: content
settings: { }
third_party_settings: { }
promote:
@ -37,21 +40,25 @@ content:
settings:
display_label: true
weight: 15
region: content
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 16
region: content
third_party_settings: { }
taxonomy_forums:
type: options_select
weight: 26
region: content
settings: { }
third_party_settings: { }
title:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
@ -59,6 +66,7 @@ content:
uid:
type: entity_reference_autocomplete
weight: 5
region: content
settings:
match_operator: CONTAINS
size: 60

View file

@ -14,11 +14,13 @@ content:
description:
type: text_textfield
weight: 0
region: content
settings: { }
third_party_settings: { }
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''

View file

@ -15,8 +15,10 @@ content:
label: hidden
type: text_default
weight: 0
region: content
settings: { }
third_party_settings: { }
links:
weight: 100
region: content
hidden: { }

View file

@ -20,21 +20,25 @@ content:
label: hidden
type: text_default
weight: 0
region: content
settings: { }
third_party_settings: { }
comment_forum:
label: hidden
type: comment_default
weight: 20
region: content
settings:
view_mode: default
pager_id: 0
third_party_settings: { }
links:
weight: 100
region: content
taxonomy_forums:
type: entity_reference_label
weight: -1
region: content
label: above
settings:
link: true

View file

@ -19,14 +19,17 @@ content:
label: hidden
type: text_summary_or_trimmed
weight: 100
region: content
settings:
trim_length: 600
third_party_settings: { }
links:
weight: 101
region: content
taxonomy_forums:
type: entity_reference_label
weight: 10
region: content
label: above
settings:
link: true

View file

@ -14,6 +14,7 @@ content:
description:
type: text_default
weight: 0
region: content
settings: { }
third_party_settings: { }
label: above

View file

@ -21,13 +21,13 @@ function forum_install() {
if (!\Drupal::service('config.installer')->isSyncing()) {
// Create a default forum so forum posts can be created.
$term = Term::create(array(
$term = Term::create([
'name' => t('General discussion'),
'description' => '',
'parent' => array(0),
'parent' => [0],
'vid' => 'forums',
'forum_container' => 0,
));
]);
$term->save();
}
}
@ -61,117 +61,117 @@ function forum_uninstall() {
* Implements hook_schema().
*/
function forum_schema() {
$schema['forum'] = array(
$schema['forum'] = [
'description' => 'Stores the relationship of nodes to forum terms.',
'fields' => array(
'nid' => array(
'fields' => [
'nid' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {node}.nid of the node.',
),
'vid' => array(
],
'vid' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: The {node}.vid of the node.',
),
'tid' => array(
],
'tid' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
),
),
'indexes' => array(
'forum_topic' => array('nid', 'tid'),
'tid' => array('tid'),
),
'primary key' => array('vid'),
'foreign keys' => array(
'forum_node' => array(
],
],
'indexes' => [
'forum_topic' => ['nid', 'tid'],
'tid' => ['tid'],
],
'primary key' => ['vid'],
'foreign keys' => [
'forum_node' => [
'table' => 'node',
'columns' => array(
'columns' => [
'nid' => 'nid',
'vid' => 'vid',
),
),
),
);
],
],
],
];
$schema['forum_index'] = array(
$schema['forum_index'] = [
'description' => 'Maintains denormalized information about node/term relationships.',
'fields' => array(
'nid' => array(
'fields' => [
'nid' => [
'description' => 'The {node}.nid this record tracks.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'title' => array(
],
'title' => [
'description' => 'The node title.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'tid' => array(
],
'tid' => [
'description' => 'The term ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
],
'sticky' => [
'description' => 'Boolean indicating whether the node is sticky.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
),
'created' => array(
],
'created' => [
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'last_comment_timestamp' => array(
],
'last_comment_timestamp' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
),
'comment_count' => array(
],
'comment_count' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The total number of comments on this node.',
),
),
'indexes' => array(
'forum_topics' => array('nid', 'tid', 'sticky', 'last_comment_timestamp'),
'created' => array('created'),
'last_comment_timestamp' => array('last_comment_timestamp'),
),
'foreign keys' => array(
'tracked_node' => array(
],
],
'indexes' => [
'forum_topics' => ['nid', 'tid', 'sticky', 'last_comment_timestamp'],
'created' => ['created'],
'last_comment_timestamp' => ['last_comment_timestamp'],
],
'foreign keys' => [
'tracked_node' => [
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'columns' => ['nid' => 'nid'],
],
'term' => [
'table' => 'taxonomy_term_data',
'columns' => array(
'columns' => [
'tid' => 'tid',
),
),
),
);
],
],
],
];
return $schema;
}

View file

@ -24,7 +24,7 @@ function forum_help($route_name, RouteMatchInterface $route_match) {
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Forum module lets you create threaded discussion forums with functionality similar to other message board systems. In a forum, users post topics and threads in nested hierarchies, allowing discussions to be categorized and grouped.') . '</p>';
$output .= '<p>' . t('The Forum module adds and uses a content type called <em>Forum topic</em>. For background information on content types, see the <a href=":node_help">Node module help page</a>.', array(':node_help' => \Drupal::url('help.page', array('name' => 'node')))) . '</p>';
$output .= '<p>' . t('The Forum module adds and uses a content type called <em>Forum topic</em>. For background information on content types, see the <a href=":node_help">Node module help page</a>.', [':node_help' => \Drupal::url('help.page', ['name' => 'node'])]) . '</p>';
$output .= '<p>' . t('A forum is represented by a hierarchical structure, consisting of:');
$output .= '<ul>';
$output .= '<li>' . t('<em>Forums</em> (for example, <em>Recipes for cooking vegetables</em>)') . '</li>';
@ -33,15 +33,15 @@ function forum_help($route_name, RouteMatchInterface $route_match) {
$output .= '<li>' . t('Optional <em>containers</em>, used to group similar forums. Forums can be placed inside containers, and vice versa.') . '</li>';
$output .= '</ul>';
$output .= '</p>';
$output .= '<p>' . t('For more information, see the <a href=":forum">online documentation for the Forum module</a>.', array(':forum' => 'https://www.drupal.org/documentation/modules/forum')) . '</p>';
$output .= '<p>' . t('For more information, see the <a href=":forum">online documentation for the Forum module</a>.', [':forum' => 'https://www.drupal.org/documentation/modules/forum']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Setting up the forum structure') . '</dt>';
$output .= '<dd>' . t('Visit the <a href=":forums">Forums page</a> to set up containers and forums to hold your discussion topics.', array(':forums' => \Drupal::url('forum.overview'))) . '</dd>';
$output .= '<dd>' . t('Visit the <a href=":forums">Forums page</a> to set up containers and forums to hold your discussion topics.', [':forums' => \Drupal::url('forum.overview')]) . '</dd>';
$output .= '<dt>' . t('Starting a discussion') . '</dt>';
$output .= '<dd>' . t('The <a href=":create-topic">Forum topic</a> link on the <a href=":content-add">Add content</a> page creates the first post of a new threaded discussion, or thread.', array(':create-topic' => \Drupal::url('node.add', array('node_type' => 'forum')), ':content-add' => \Drupal::url('node.add_page'))) . '</dd>';
$output .= '<dd>' . t('The <a href=":create-topic">Forum topic</a> link on the <a href=":content-add">Add content</a> page creates the first post of a new threaded discussion, or thread.', [':create-topic' => \Drupal::url('node.add', ['node_type' => 'forum']), ':content-add' => \Drupal::url('node.add_page')]) . '</dd>';
$output .= '<dt>' . t('Navigating in the forum') . '</dt>';
$output .= '<dd>' . t('Enabling the Forum module provides a default <em>Forums</em> menu item in the Tools menu that links to the <a href=":forums">Forums page</a>.', array(':forums' => \Drupal::url('forum.index'))) . '</dd>';
$output .= '<dd>' . t('Enabling the Forum module provides a default <em>Forums</em> menu item in the Tools menu that links to the <a href=":forums">Forums page</a>.', [':forums' => \Drupal::url('forum.index')]) . '</dd>';
$output .= '<dt>' . t('Moving forum topics') . '</dt>';
$output .= '<dd>' . t('A forum topic (and all of its comments) may be moved between forums by selecting a different forum while editing a forum topic. When moving a forum topic between forums, the <em>Leave shadow copy</em> option creates a link in the original forum pointing to the new location.') . '</dd>';
$output .= '<dt>' . t('Locking and disabling comments') . '</dt>';
@ -51,21 +51,21 @@ function forum_help($route_name, RouteMatchInterface $route_match) {
case 'forum.overview':
$output = '<p>' . t('Forums contain forum topics. Use containers to group related forums.') . '</p>';
$more_help_link = array(
$more_help_link = [
'#type' => 'link',
'#url' => Url::fromRoute('help.page', ['name' => 'forum']),
'#title' => t('More help'),
'#attributes' => array(
'class' => array('icon-help'),
),
);
$container = array(
'#attributes' => [
'class' => ['icon-help'],
],
];
$container = [
'#theme' => 'container',
'#children' => $more_help_link,
'#attributes' => array(
'class' => array('more-link'),
),
);
'#attributes' => [
'class' => ['more-link'],
],
];
$output .= \Drupal::service('renderer')->renderPlain($container);
return $output;
@ -76,7 +76,7 @@ function forum_help($route_name, RouteMatchInterface $route_match) {
return '<p>' . t('A forum holds related forum topics.') . '</p>';
case 'forum.settings':
return '<p>' . t('Adjust the display of your forum topics. Organize the forums on the <a href=":forum-structure">forum structure page</a>.', array(':forum-structure' => \Drupal::url('forum.overview'))) . '</p>';
return '<p>' . t('Adjust the display of your forum topics. Organize the forums on the <a href=":forum-structure">forum structure page</a>.', [':forum-structure' => \Drupal::url('forum.overview')]) . '</p>';
}
}
@ -84,20 +84,20 @@ function forum_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_theme().
*/
function forum_theme() {
return array(
'forums' => array(
'variables' => array('forums' => array(), 'topics' => array(), 'topics_pager' => array(), 'parents' => NULL, 'term' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL, 'header' => array()),
),
'forum_list' => array(
'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),
),
'forum_icon' => array(
'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0, 'first_new' => FALSE),
),
'forum_submitted' => array(
'variables' => array('topic' => NULL),
),
);
return [
'forums' => [
'variables' => ['forums' => [], 'topics' => [], 'topics_pager' => [], 'parents' => NULL, 'term' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL, 'header' => []],
],
'forum_list' => [
'variables' => ['forums' => NULL, 'parents' => NULL, 'tid' => NULL],
],
'forum_icon' => [
'variables' => ['new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0, 'first_new' => FALSE],
],
'forum_submitted' => [
'variables' => ['topic' => NULL],
],
];
}
/**
@ -158,7 +158,7 @@ function forum_node_presave(EntityInterface $node) {
$old_tid = \Drupal::service('forum.index_storage')->getOriginalTermId($node);
if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) {
// A shadow copy needs to be created. Retain new term and add old term.
$node->taxonomy_forums[count($node->taxonomy_forums)] = array('target_id' => $old_tid);
$node->taxonomy_forums[count($node->taxonomy_forums)] = ['target_id' => $old_tid];
}
}
}
@ -241,7 +241,7 @@ function forum_node_predelete(EntityInterface $node) {
* Implements hook_ENTITY_TYPE_storage_load() for node entities.
*/
function forum_node_storage_load($nodes) {
$node_vids = array();
$node_vids = [];
foreach ($nodes as $node) {
if (\Drupal::service('forum_manager')->checkNodeType($node)) {
$node_vids[] = $node->getRevisionId();
@ -289,10 +289,10 @@ function forum_form_taxonomy_vocabulary_form_alter(&$form, FormStateInterface $f
$vid = \Drupal::config('forum.settings')->get('vocabulary');
$vocabulary = $form_state->getFormObject()->getEntity();
if ($vid == $vocabulary->id()) {
$form['help_forum_vocab'] = array(
$form['help_forum_vocab'] = [
'#markup' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'),
'#weight' => -1,
);
];
// Forum's vocabulary always has single hierarchy. Forums and containers
// have only one parent or no parent for root items. By default this value
// is 0.
@ -324,13 +324,13 @@ function forum_form_node_form_alter(&$form, FormStateInterface $form_state, $for
$forum_terms = $node->taxonomy_forums;
// If editing, give option to leave shadows.
$shadow = (count($forum_terms) > 1);
$form['shadow'] = array(
$form['shadow'] = [
'#type' => 'checkbox',
'#title' => t('Leave shadow copy'),
'#default_value' => $shadow,
'#description' => t('If you move this topic, you can leave a link in the old forum to the new forum.'),
);
$form['forum_tid'] = array('#type' => 'value', '#value' => $node->forum_tid);
];
$form['forum_tid'] = ['#type' => 'value', '#value' => $node->forum_tid];
}
if (isset($form['taxonomy_forums'])) {
@ -361,7 +361,7 @@ function forum_preprocess_block(&$variables) {
* Implements hook_theme_suggestions_HOOK().
*/
function forum_theme_suggestions_forums(array $variables) {
$suggestions = array();
$suggestions = [];
$tid = $variables['term']->id();
// Provide separate template suggestions based on what's being output. Topic
@ -408,24 +408,24 @@ function template_preprocess_forums(&$variables) {
$variables['tid'] = $variables['term']->id();
if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) {
if (!empty($variables['forums'])) {
$variables['forums'] = array(
$variables['forums'] = [
'#theme' => 'forum_list',
'#forums' => $variables['forums'],
'#parents' => $variables['parents'],
'#tid' => $variables['tid'],
);
];
}
if ($variables['term'] && empty($variables['term']->forum_container->value) && !empty($variables['topics'])) {
$forum_topic_list_header = $variables['header'];
$table = array(
$table = [
'#theme' => 'table__forum_topic_list',
'#responsive' => FALSE,
'#attributes' => array('id' => 'forum-topic-' . $variables['tid']),
'#header' => array(),
'#rows' => array(),
);
'#attributes' => ['id' => 'forum-topic-' . $variables['tid']],
'#header' => [],
'#rows' => [],
];
if (!empty($forum_topic_list_header)) {
$table['#header'] = $forum_topic_list_header;
@ -433,14 +433,14 @@ function template_preprocess_forums(&$variables) {
/** @var \Drupal\node\NodeInterface $topic */
foreach ($variables['topics'] as $id => $topic) {
$variables['topics'][$id]->icon = array(
$variables['topics'][$id]->icon = [
'#theme' => 'forum_icon',
'#new_posts' => $topic->new,
'#num_posts' => $topic->comment_count,
'#comment_mode' => $topic->comment_mode,
'#sticky' => $topic->isSticky(),
'#first_new' => $topic->first_new,
);
];
// We keep the actual tid in forum table, if it's different from the
// current tid then it means the topic appears in two forums, one of
@ -455,16 +455,16 @@ function template_preprocess_forums(&$variables) {
$variables['topics'][$id]->title_link = \Drupal::l($topic->getTitle(), $topic->urlInfo());
$variables['topics'][$id]->message = '';
}
$forum_submitted = array('#theme' => 'forum_submitted', '#topic' => (object) array(
$forum_submitted = ['#theme' => 'forum_submitted', '#topic' => (object) [
'uid' => $topic->getOwnerId(),
'name' => $topic->getOwner()->getDisplayName(),
'created' => $topic->getCreatedTime(),
));
]];
$variables['topics'][$id]->submitted = drupal_render($forum_submitted);
$forum_submitted = array(
$forum_submitted = [
'#theme' => 'forum_submitted',
'#topic' => isset($topic->last_reply) ? $topic->last_reply : NULL,
);
];
$variables['topics'][$id]->last_reply = drupal_render($forum_submitted);
$variables['topics'][$id]->new_text = '';
@ -473,28 +473,28 @@ function template_preprocess_forums(&$variables) {
if ($topic->new_replies) {
$page_number = \Drupal::entityManager()->getStorage('comment')
->getNewCommentPageNumber($topic->comment_count, $topic->new_replies, $topic, 'comment_forum');
$query = $page_number ? array('page' => $page_number) : NULL;
$variables['topics'][$id]->new_text = \Drupal::translation()->formatPlural($topic->new_replies, '1 new post<span class="visually-hidden"> in topic %title</span>', '@count new posts<span class="visually-hidden"> in topic %title</span>', array('%title' => $variables['topics'][$id]->label()));
$query = $page_number ? ['page' => $page_number] : NULL;
$variables['topics'][$id]->new_text = \Drupal::translation()->formatPlural($topic->new_replies, '1 new post<span class="visually-hidden"> in topic %title</span>', '@count new posts<span class="visually-hidden"> in topic %title</span>', ['%title' => $variables['topics'][$id]->label()]);
$variables['topics'][$id]->new_url = \Drupal::url('entity.node.canonical', ['node' => $topic->id()], ['query' => $query, 'fragment' => 'new']);
}
// Build table rows from topics.
$row = array();
$row[] = array(
'data' => array(
$row = [];
$row[] = [
'data' => [
$topic->icon,
array(
[
'#markup' => '<div class="forum__title"><div>' . $topic->title_link . '</div><div>' . $topic->submitted . '</div></div>',
),
),
'class' => array('forum__topic'),
);
],
],
'class' => ['forum__topic'],
];
if ($topic->moved) {
$row[] = array(
$row[] = [
'data' => $topic->message,
'colspan' => '2',
);
];
}
else {
$new_replies = '';
@ -502,27 +502,27 @@ function template_preprocess_forums(&$variables) {
$new_replies = '<br /><a href="' . $topic->new_url . '">' . $topic->new_text . '</a>';
}
$row[] = array(
$row[] = [
'data' => [
[
'#prefix' => $topic->comment_count,
'#markup' => $new_replies,
],
],
'class' => array('forum__replies'),
);
$row[] = array(
'class' => ['forum__replies'],
];
$row[] = [
'data' => $topic->last_reply,
'class' => array('forum__last-reply'),
);
'class' => ['forum__last-reply'],
];
}
$table['#rows'][] = $row;
}
$variables['topics'] = $table;
$variables['topics_pager'] = array(
$variables['topics_pager'] = [
'#type' => 'pager',
);
];
}
}
}
@ -545,7 +545,7 @@ function template_preprocess_forum_list(&$variables) {
$row = 0;
// Sanitize each forum so that the template can safely print the data.
foreach ($variables['forums'] as $id => $forum) {
$variables['forums'][$id]->description = array('#markup' => $forum->description->value);
$variables['forums'][$id]->description = ['#markup' => $forum->description->value];
$variables['forums'][$id]->link = forum_uri($forum);
$variables['forums'][$id]->name = $forum->label();
$variables['forums'][$id]->is_container = !empty($forum->forum_container->value);
@ -561,20 +561,20 @@ function template_preprocess_forum_list(&$variables) {
if ($user->isAuthenticated()) {
$variables['forums'][$id]->new_topics = \Drupal::service('forum_manager')->unreadTopics($forum->id(), $user->id());
if ($variables['forums'][$id]->new_topics) {
$variables['forums'][$id]->new_text = \Drupal::translation()->formatPlural($variables['forums'][$id]->new_topics, '1 new post<span class="visually-hidden"> in forum %title</span>', '@count new posts<span class="visually-hidden"> in forum %title</span>', array('%title' => $variables['forums'][$id]->label()));
$variables['forums'][$id]->new_text = \Drupal::translation()->formatPlural($variables['forums'][$id]->new_topics, '1 new post<span class="visually-hidden"> in forum %title</span>', '@count new posts<span class="visually-hidden"> in forum %title</span>', ['%title' => $variables['forums'][$id]->label()]);
$variables['forums'][$id]->new_url = \Drupal::url('forum.page', ['taxonomy_term' => $forum->id()], ['fragment' => 'new']);
$variables['forums'][$id]->icon_class = 'new';
$variables['forums'][$id]->icon_title = t('New posts');
}
$variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics;
}
$forum_submitted = array('#theme' => 'forum_submitted', '#topic' => $forum->last_post);
$forum_submitted = ['#theme' => 'forum_submitted', '#topic' => $forum->last_post];
$variables['forums'][$id]->last_reply = drupal_render($forum_submitted);
}
$variables['pager'] = array(
$variables['pager'] = [
'#type' => 'pager',
);
];
// Give meaning to $tid for themers. $tid actually stands for term ID.
$variables['forum_id'] = $variables['tid'];
@ -635,7 +635,7 @@ function template_preprocess_forum_icon(&$variables) {
function template_preprocess_forum_submitted(&$variables) {
$variables['author'] = '';
if (isset($variables['topic']->uid)) {
$username = array('#theme' => 'username', '#account' => User::load($variables['topic']->uid));
$username = ['#theme' => 'username', '#account' => User::load($variables['topic']->uid)];
$variables['author'] = drupal_render($username);
}
$variables['time'] = isset($variables['topic']->created) ? \Drupal::service('date.formatter')->formatTimeDiffSince($variables['topic']->created) : '';

View file

@ -24,5 +24,5 @@ services:
class: Drupal\forum\ForumUninstallValidator
tags:
- { name: module_install.uninstall_validator }
arguments: ['@entity.manager', '@entity.query', '@config.factory', '@string_translation']
arguments: ['@entity_type.manager', '@config.factory', '@string_translation']
lazy: true

View file

@ -11,147 +11,147 @@
function forum_views_data() {
$data['forum_index']['table']['group'] = t('Forum');
$data['forum_index']['table']['base'] = array(
$data['forum_index']['table']['base'] = [
'field' => 'nid',
'title' => t('Forum content'),
'access query tag' => 'node_access',
);
];
$data['forum_index']['nid'] = array(
$data['forum_index']['nid'] = [
'title' => t('Nid'),
'help' => t('The content ID of the forum index entry.'),
'field' => array(
'field' => [
'id' => 'numeric',
),
'filter' => array(
],
'filter' => [
'id' => 'numeric',
),
'argument' => array(
],
'argument' => [
'id' => 'numeric',
),
'sort' => array(
],
'sort' => [
'id' => 'standard',
),
'relationship' => array(
],
'relationship' => [
'base' => 'node',
'base field' => 'nid',
'label' => t('Node'),
),
);
],
];
$data['forum_index']['title'] = array(
$data['forum_index']['title'] = [
'title' => t('Title'),
'help' => t('The content title.'),
'field' => array(
'field' => [
'id' => 'standard',
'link_to_node default' => TRUE,
),
'sort' => array(
],
'sort' => [
'id' => 'standard',
),
'filter' => array(
],
'filter' => [
'id' => 'string',
),
'argument' => array(
],
'argument' => [
'id' => 'string',
),
);
],
];
$data['forum_index']['tid'] = array(
$data['forum_index']['tid'] = [
'title' => t('Has taxonomy term ID'),
'help' => t('Display content if it has the selected taxonomy terms.'),
'argument' => array(
'argument' => [
'id' => 'taxonomy_index_tid',
'name table' => 'taxonomy_term_data',
'name field' => 'name',
'empty field name' => t('Uncategorized'),
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
),
'field' => array(
],
'field' => [
'id' => 'numeric',
),
'filter' => array(
],
'filter' => [
'title' => t('Has taxonomy term'),
'id' => 'taxonomy_index_tid',
'hierarchy table' => 'taxonomy_term_hierarchy',
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
'allow empty' => TRUE,
),
'relationship' => array(
],
'relationship' => [
'base' => 'taxonomy_term',
'base field' => 'tid',
'label' => t('Term'),
),
);
],
];
$data['forum_index']['created'] = array(
$data['forum_index']['created'] = [
'title' => t('Post date'),
'help' => t('The date the content was posted.'),
'field' => array(
'field' => [
'id' => 'date',
),
'sort' => array(
],
'sort' => [
'id' => 'date'
),
'filter' => array(
],
'filter' => [
'id' => 'date',
),
);
],
];
$data['forum_index']['sticky'] = array(
$data['forum_index']['sticky'] = [
'title' => t('Sticky'),
'help' => t('Whether or not the content is sticky.'),
'field' => array(
'field' => [
'id' => 'boolean',
'click sortable' => TRUE,
'output formats' => array(
'sticky' => array(t('Sticky'), t('Not sticky')),
),
),
'filter' => array(
'output formats' => [
'sticky' => [t('Sticky'), t('Not sticky')],
],
],
'filter' => [
'id' => 'boolean',
'label' => t('Sticky'),
'type' => 'yes-no',
),
'sort' => array(
],
'sort' => [
'id' => 'standard',
'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
),
);
],
];
$data['forum_index']['last_comment_timestamp'] = array(
$data['forum_index']['last_comment_timestamp'] = [
'title' => t('Last comment time'),
'help' => t('Date and time of when the last comment was posted.'),
'field' => array(
'field' => [
'id' => 'comment_last_timestamp',
),
'sort' => array(
],
'sort' => [
'id' => 'date',
),
'filter' => array(
],
'filter' => [
'id' => 'date',
),
);
],
];
$data['forum_index']['comment_count'] = array(
$data['forum_index']['comment_count'] = [
'title' => t('Comment count'),
'help' => t('The number of comments a node has.'),
'field' => array(
'field' => [
'id' => 'numeric',
),
'filter' => array(
],
'filter' => [
'id' => 'numeric',
),
'sort' => array(
],
'sort' => [
'id' => 'standard',
),
'argument' => array(
],
'argument' => [
'id' => 'standard',
),
);
],
];
return $data;
}

View file

@ -32,9 +32,9 @@ class ForumNodeBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {
foreach ($parents as $parent) {
$breadcrumb->addCacheableDependency($parent);
$breadcrumb->addLink(Link::createFromRoute($parent->label(), 'forum.page',
array(
[
'taxonomy_term' => $parent->id(),
)
]
));
}
}

View file

@ -207,9 +207,9 @@ class ForumController extends ControllerBase {
* @return array
* A render array.
*/
protected function build($forums, TermInterface $term, $topics = array(), $parents = array(), $header = array()) {
protected function build($forums, TermInterface $term, $topics = [], $parents = [], $header = []) {
$config = $this->config('forum.settings');
$build = array(
$build = [
'#theme' => 'forums',
'#forums' => $forums,
'#topics' => $topics,
@ -218,9 +218,9 @@ class ForumController extends ControllerBase {
'#term' => $term,
'#sortby' => $config->get('topics.order'),
'#forums_per_page' => $config->get('topics.page_limit'),
);
];
if (empty($term->forum_container->value)) {
$build['#attached']['feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->getName());
$build['#attached']['feed'][] = ['taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->getName()];
}
$this->renderer->addCacheableDependency($build, $config);
@ -252,10 +252,10 @@ class ForumController extends ControllerBase {
*/
public function addForum() {
$vid = $this->config('forum.settings')->get('vocabulary');
$taxonomy_term = $this->termStorage->create(array(
$taxonomy_term = $this->termStorage->create([
'vid' => $vid,
'forum_controller' => 0,
));
]);
return $this->entityFormBuilder()->getForm($taxonomy_term, 'forum');
}
@ -267,10 +267,10 @@ class ForumController extends ControllerBase {
*/
public function addContainer() {
$vid = $this->config('forum.settings')->get('vocabulary');
$taxonomy_term = $this->termStorage->create(array(
$taxonomy_term = $this->termStorage->create([
'vid' => $vid,
'forum_container' => 1,
));
]);
return $this->entityFormBuilder()->getForm($taxonomy_term, 'container');
}
@ -325,10 +325,10 @@ class ForumController extends ControllerBase {
$links['login'] = [
'#attributes' => ['class' => ['action-links']],
'#theme' => 'menu_local_action',
'#link' => array(
'#link' => [
'title' => $this->t('Log in to post new content in the forum.'),
'url' => Url::fromRoute('user.login', [], ['query' => $this->getDestinationArray()]),
),
],
];
}
}

View file

@ -30,7 +30,7 @@ class DeleteForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the forum %label?', array('%label' => $this->taxonomyTerm->label()));
return $this->t('Are you sure you want to delete the forum %label?', ['%label' => $this->taxonomyTerm->label()]);
}
/**
@ -61,8 +61,8 @@ class DeleteForm extends ConfirmFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->taxonomyTerm->delete();
drupal_set_message($this->t('The forum %label and all sub-forums have been deleted.', array('%label' => $this->taxonomyTerm->label())));
$this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', array('%label' => $this->taxonomyTerm->label()));
drupal_set_message($this->t('The forum %label and all sub-forums have been deleted.', ['%label' => $this->taxonomyTerm->label()]));
$this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', ['%label' => $this->taxonomyTerm->label()]);
$form_state->setRedirectUrl($this->getCancelUrl());
}

View file

@ -50,7 +50,7 @@ class ForumForm extends TermForm {
$form['parent']['#tree'] = TRUE;
$form['parent'][0] = $this->forumParentSelect($taxonomy_term->id(), $this->t('Parent'));
$form['#theme_wrappers'] = array('form__forum');
$form['#theme_wrappers'] = ['form__forum'];
$this->forumFormType = $this->t('forum');
return $form;
}
@ -62,7 +62,7 @@ class ForumForm extends TermForm {
$term = parent::buildEntity($form, $form_state);
// Assign parents from forum parent select field.
$term->parent = array($form_state->getValue(array('parent', 0)));
$term->parent = [$form_state->getValue(['parent', 0])];
return $term;
}
@ -81,14 +81,14 @@ class ForumForm extends TermForm {
$view_link = $term->link($term->getName());
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created new @type %term.', array('%term' => $view_link, '@type' => $this->forumFormType)));
$this->logger('forum')->notice('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link));
drupal_set_message($this->t('Created new @type %term.', ['%term' => $view_link, '@type' => $this->forumFormType]));
$this->logger('forum')->notice('Created new @type %term.', ['%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link]);
$form_state->setValue('tid', $term->id());
break;
case SAVED_UPDATED:
drupal_set_message($this->t('The @type %term has been updated.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
$this->logger('forum')->notice('Updated @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link));
drupal_set_message($this->t('The @type %term has been updated.', ['%term' => $term->getName(), '@type' => $this->forumFormType]));
$this->logger('forum')->notice('Updated @type %term.', ['%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link]);
break;
}
@ -155,14 +155,14 @@ class ForumForm extends TermForm {
$description = $this->t('Forums may be placed at the top (root) level, or inside another container or forum.');
return array(
return [
'#type' => 'select',
'#title' => $title,
'#default_value' => $parent,
'#options' => $options,
'#description' => $description,
'#required' => TRUE,
);
];
}
}

View file

@ -80,10 +80,10 @@ class Overview extends OverviewTerms {
unset($form['actions']['reset_alphabetical']);
// Use the existing taxonomy overview submit handler.
$form['terms']['#empty'] = $this->t('No containers or forums available. <a href=":container">Add container</a> or <a href=":forum">Add forum</a>.', array(
$form['terms']['#empty'] = $this->t('No containers or forums available. <a href=":container">Add container</a> or <a href=":forum">Add forum</a>.', [
':container' => $this->url('forum.add_container'),
':forum' => $this->url('forum.add_forum')
));
]);
return $form;
}

View file

@ -23,7 +23,7 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
* @param \Drupal\Core\Database\Connection $database
* The current database connection.
*/
function __construct(Connection $database) {
public function __construct(Connection $database) {
$this->database = $database;
}
@ -31,7 +31,7 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
* {@inheritdoc}
*/
public function getOriginalTermId(NodeInterface $node) {
return $this->database->queryRange("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->id()))->fetchField();
return $this->database->queryRange("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, [':nid' => $node->id()])->fetchField();
}
/**
@ -39,11 +39,11 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
*/
public function create(NodeInterface $node) {
$this->database->insert('forum')
->fields(array(
->fields([
'tid' => $node->forum_tid,
'vid' => $node->getRevisionId(),
'nid' => $node->id(),
))
])
->execute();
}
@ -52,7 +52,7 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
*/
public function read(array $vids) {
return $this->database->select('forum', 'f')
->fields('f', array('nid', 'tid'))
->fields('f', ['nid', 'tid'])
->condition('f.vid', $vids, 'IN')
->execute();
}
@ -81,7 +81,7 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
*/
public function update(NodeInterface $node) {
$this->database->update('forum')
->fields(array('tid' => $node->forum_tid))
->fields(['tid' => $node->forum_tid])
->condition('vid', $node->getRevisionId())
->execute();
}
@ -91,22 +91,22 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
*/
public function updateIndex(NodeInterface $node) {
$nid = $node->id();
$count = $this->database->query("SELECT COUNT(cid) FROM {comment_field_data} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_name = 'comment_forum' AND c.entity_type = 'node' AND c.status = :status AND c.default_langcode = 1", array(
$count = $this->database->query("SELECT COUNT(cid) FROM {comment_field_data} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_name = 'comment_forum' AND c.entity_type = 'node' AND c.status = :status AND c.default_langcode = 1", [
':nid' => $nid,
':status' => CommentInterface::PUBLISHED,
))->fetchField();
])->fetchField();
if ($count > 0) {
// Comments exist.
$last_reply = $this->database->queryRange("SELECT cid, name, created, uid FROM {comment_field_data} WHERE entity_id = :nid AND field_name = 'comment_forum' AND entity_type = 'node' AND status = :status AND default_langcode = 1 ORDER BY cid DESC", 0, 1, array(
$last_reply = $this->database->queryRange("SELECT cid, name, created, uid FROM {comment_field_data} WHERE entity_id = :nid AND field_name = 'comment_forum' AND entity_type = 'node' AND status = :status AND default_langcode = 1 ORDER BY cid DESC", 0, 1, [
':nid' => $nid,
':status' => CommentInterface::PUBLISHED,
))->fetchObject();
])->fetchObject();
$this->database->update('forum_index')
->fields( array(
->fields( [
'comment_count' => $count,
'last_comment_timestamp' => $last_reply->created,
))
])
->condition('nid', $nid)
->execute();
}
@ -114,10 +114,10 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
// Comments do not exist.
// @todo This should be actually filtering on the desired node language
$this->database->update('forum_index')
->fields( array(
->fields( [
'comment_count' => 0,
'last_comment_timestamp' => $node->getCreatedTime(),
))
])
->condition('nid', $nid)
->execute();
}
@ -128,11 +128,11 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
*/
public function createIndex(NodeInterface $node) {
$query = $this->database->insert('forum_index')
->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
->fields(['nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp']);
foreach ($node->getTranslationLanguages() as $langcode => $language) {
$translation = $node->getTranslation($langcode);
foreach ($translation->taxonomy_forums as $item) {
$query->values(array(
$query->values([
'nid' => $node->id(),
'title' => $translation->label(),
'tid' => $item->target_id,
@ -140,7 +140,7 @@ class ForumIndexStorage implements ForumIndexStorageInterface {
'created' => $node->getCreatedTime(),
'comment_count' => 0,
'last_comment_timestamp' => $node->getCreatedTime(),
));
]);
}
}
$query->execute();

View file

@ -75,28 +75,28 @@ class ForumManager implements ForumManagerInterface {
*
* @var array
*/
protected $lastPostData = array();
protected $lastPostData = [];
/**
* Array of forum statistics keyed by forum (term) id.
*
* @var array
*/
protected $forumStatistics = array();
protected $forumStatistics = [];
/**
* Array of forum children keyed by parent forum (term) id.
*
* @var array
*/
protected $forumChildren = array();
protected $forumChildren = [];
/**
* Array of history keyed by nid.
*
* @var array
*/
protected $history = array();
protected $history = [];
/**
* Cached forum index.
@ -135,11 +135,11 @@ class ForumManager implements ForumManagerInterface {
$forum_per_page = $config->get('topics.page_limit');
$sortby = $config->get('topics.order');
$header = array(
array('data' => $this->t('Topic'), 'field' => 'f.title'),
array('data' => $this->t('Replies'), 'field' => 'f.comment_count'),
array('data' => $this->t('Last reply'), 'field' => 'f.last_comment_timestamp'),
);
$header = [
['data' => $this->t('Topic'), 'field' => 'f.title'],
['data' => $this->t('Replies'), 'field' => 'f.comment_count'],
['data' => $this->t('Last reply'), 'field' => 'f.last_comment_timestamp'],
];
$order = $this->getTopicOrder($sortby);
for ($i = 0; $i < count($header); $i++) {
@ -168,7 +168,7 @@ class ForumManager implements ForumManagerInterface {
$query->setCountQuery($count_query);
$result = $query->execute();
$nids = array();
$nids = [];
foreach ($result as $record) {
$nids[] = $record->nid;
}
@ -177,15 +177,15 @@ class ForumManager implements ForumManagerInterface {
$query = $this->connection->select('node_field_data', 'n')
->extend('Drupal\Core\Database\Query\TableSortExtender');
$query->fields('n', array('nid'));
$query->fields('n', ['nid']);
$query->join('comment_entity_statistics', 'ces', "n.nid = ces.entity_id AND ces.field_name = 'comment_forum' AND ces.entity_type = 'node'");
$query->fields('ces', array(
$query->fields('ces', [
'cid',
'last_comment_uid',
'last_comment_timestamp',
'comment_count'
));
]);
$query->join('forum_index', 'f', 'f.nid = n.nid');
$query->addField('f', 'tid', 'forum_tid');
@ -205,7 +205,7 @@ class ForumManager implements ForumManagerInterface {
// and just fall back to the default language.
->condition('n.default_langcode', 1);
$result = array();
$result = [];
foreach ($query->execute() as $row) {
$topic = $nodes[$row->nid];
$topic->comment_mode = $topic->comment_forum->status;
@ -217,10 +217,10 @@ class ForumManager implements ForumManagerInterface {
}
}
else {
$result = array();
$result = [];
}
$topics = array();
$topics = [];
$first_new_found = FALSE;
foreach ($result as $topic) {
if ($account->isAuthenticated()) {
@ -258,7 +258,7 @@ class ForumManager implements ForumManagerInterface {
$topics[$topic->id()] = $topic;
}
return array('topics' => $topics, 'header' => $header);
return ['topics' => $topics, 'header' => $header];
}
@ -280,16 +280,16 @@ class ForumManager implements ForumManagerInterface {
protected function getTopicOrder($sortby) {
switch ($sortby) {
case static::NEWEST_FIRST:
return array('field' => 'f.last_comment_timestamp', 'sort' => 'desc');
return ['field' => 'f.last_comment_timestamp', 'sort' => 'desc'];
case static::OLDEST_FIRST:
return array('field' => 'f.last_comment_timestamp', 'sort' => 'asc');
return ['field' => 'f.last_comment_timestamp', 'sort' => 'asc'];
case static::MOST_POPULAR_FIRST:
return array('field' => 'f.comment_count', 'sort' => 'desc');
return ['field' => 'f.comment_count', 'sort' => 'desc'];
case static::LEAST_POPULAR_FIRST:
return array('field' => 'f.comment_count', 'sort' => 'asc');
return ['field' => 'f.comment_count', 'sort' => 'asc'];
}
}
@ -309,7 +309,7 @@ class ForumManager implements ForumManagerInterface {
protected function lastVisit($nid, AccountInterface $account) {
if (empty($this->history[$nid])) {
$result = $this->connection->select('history', 'h')
->fields('h', array('nid', 'timestamp'))
->fields('h', ['nid', 'timestamp'])
->condition('uid', $account->id())
->execute();
foreach ($result as $t) {
@ -334,13 +334,13 @@ class ForumManager implements ForumManagerInterface {
}
// Query "Last Post" information for this forum.
$query = $this->connection->select('node_field_data', 'n');
$query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $tid));
$query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', [':tid' => $tid]);
$query->join('comment_entity_statistics', 'ces', "n.nid = ces.entity_id AND ces.field_name = 'comment_forum' AND ces.entity_type = 'node'");
$query->join('users_field_data', 'u', 'ces.last_comment_uid = u.uid AND u.default_langcode = 1');
$query->addExpression('CASE ces.last_comment_uid WHEN 0 THEN ces.last_comment_name ELSE u.name END', 'last_comment_name');
$topic = $query
->fields('ces', array('last_comment_timestamp', 'last_comment_uid'))
->fields('ces', ['last_comment_timestamp', 'last_comment_uid'])
->condition('n.status', 1)
->orderBy('last_comment_timestamp', 'DESC')
->range(0, 1)
@ -378,7 +378,7 @@ class ForumManager implements ForumManagerInterface {
$query->addExpression('COUNT(n.nid)', 'topic_count');
$query->addExpression('SUM(ces.comment_count)', 'comment_count');
$this->forumStatistics = $query
->fields('f', array('tid'))
->fields('f', ['tid'])
->condition('n.status', 1)
->condition('n.default_langcode', 1)
->groupBy('tid')
@ -399,7 +399,7 @@ class ForumManager implements ForumManagerInterface {
if (!empty($this->forumChildren[$tid])) {
return $this->forumChildren[$tid];
}
$forums = array();
$forums = [];
$_forums = $this->entityManager->getStorage('taxonomy_term')->loadTree($vid, $tid, NULL, TRUE);
foreach ($_forums as $forum) {
// Merge in the topic and post counters.
@ -430,13 +430,13 @@ class ForumManager implements ForumManagerInterface {
}
$vid = $this->configFactory->get('forum.settings')->get('vocabulary');
$index = $this->entityManager->getStorage('taxonomy_term')->create(array(
$index = $this->entityManager->getStorage('taxonomy_term')->create([
'tid' => 0,
'container' => 1,
'parents' => array(),
'parents' => [],
'isIndex' => TRUE,
'vid' => $vid
));
]);
// Load the tree below.
$index->forums = $this->getChildren($vid, 0);
@ -451,7 +451,7 @@ class ForumManager implements ForumManagerInterface {
// Reset the index.
$this->index = NULL;
// Reset history.
$this->history = array();
$this->history = [];
}
/**
@ -475,8 +475,8 @@ class ForumManager implements ForumManagerInterface {
*/
public function unreadTopics($term, $uid) {
$query = $this->connection->select('node_field_data', 'n');
$query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $term));
$query->leftJoin('history', 'h', 'n.nid = h.nid AND h.uid = :uid', array(':uid' => $uid));
$query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', [':tid' => $term]);
$query->leftJoin('history', 'h', 'n.nid = h.nid AND h.uid = :uid', [':uid' => $uid]);
$query->addExpression('COUNT(n.nid)', 'count');
return $query
->condition('status', 1)
@ -506,10 +506,10 @@ class ForumManager implements ForumManagerInterface {
public function __wakeup() {
$this->defaultWakeup();
// Initialize static cache.
$this->history = array();
$this->lastPostData = array();
$this->forumChildren = array();
$this->forumStatistics = array();
$this->history = [];
$this->lastPostData = [];
$this->forumChildren = [];
$this->forumStatistics = [];
$this->index = NULL;
}

View file

@ -30,35 +30,35 @@ class ForumSettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('forum.settings');
$options = array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500);
$form['forum_hot_topic'] = array(
$options = [5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500];
$form['forum_hot_topic'] = [
'#type' => 'select',
'#title' => $this->t('Hot topic threshold'),
'#default_value' => $config->get('topics.hot_threshold'),
'#options' => array_combine($options, $options),
'#description' => $this->t('The number of replies a topic must have to be considered "hot".'),
);
$options = array(10, 25, 50, 75, 100);
$form['forum_per_page'] = array(
];
$options = [10, 25, 50, 75, 100];
$form['forum_per_page'] = [
'#type' => 'select',
'#title' => $this->t('Topics per page'),
'#default_value' => $config->get('topics.page_limit'),
'#options' => array_combine($options, $options),
'#description' => $this->t('Default number of forum topics displayed per page.'),
);
$forder = array(
];
$forder = [
1 => $this->t('Date - newest first'),
2 => $this->t('Date - oldest first'),
3 => $this->t('Posts - most active first'),
4 => $this->t('Posts - least active first')
);
$form['forum_order'] = array(
];
$form['forum_order'] = [
'#type' => 'radios',
'#title' => $this->t('Default order'),
'#default_value' => $config->get('topics.order'),
'#options' => $forder,
'#description' => $this->t('Default display order for topics.'),
);
];
return parent::buildForm($form, $form_state);
}

View file

@ -3,8 +3,7 @@
namespace Drupal\forum;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
@ -19,18 +18,11 @@ class ForumUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* The field storage config storage.
* The entity type manager.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $vocabularyStorage;
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
protected $entityTypeManager;
/**
* The config factory.
@ -42,18 +34,15 @@ class ForumUninstallValidator implements ModuleUninstallValidatorInterface {
/**
* Constructs a new ForumUninstallValidator.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(EntityManagerInterface $entity_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation) {
$this->vocabularyStorage = $entity_manager->getStorage('taxonomy_vocabulary');
$this->queryFactory = $query_factory;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation) {
$this->entityTypeManager = $entity_type_manager;
$this->configFactory = $config_factory;
$this->stringTranslation = $string_translation;
}
@ -94,7 +83,7 @@ class ForumUninstallValidator implements ModuleUninstallValidatorInterface {
* TRUE if there are forum nodes, FALSE otherwise.
*/
protected function hasForumNodes() {
$nodes = $this->queryFactory->get('node')
$nodes = $this->entityTypeManager->getStorage('node')->getQuery()
->condition('type', 'forum')
->accessCheck(FALSE)
->range(0, 1)
@ -112,7 +101,7 @@ class ForumUninstallValidator implements ModuleUninstallValidatorInterface {
* TRUE if there are terms for this vocabulary, FALSE otherwise.
*/
protected function hasTermsForVocabulary(VocabularyInterface $vocabulary) {
$terms = $this->queryFactory->get('taxonomy_term')
$terms = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery()
->condition('vid', $vocabulary->id())
->accessCheck(FALSE)
->range(0, 1)
@ -128,7 +117,7 @@ class ForumUninstallValidator implements ModuleUninstallValidatorInterface {
*/
protected function getForumVocabulary() {
$vid = $this->configFactory->get('forum.settings')->get('vocabulary');
return $this->vocabularyStorage->load($vid);
return $this->entityTypeManager->getStorage('taxonomy_vocabulary')->load($vid);
}
}

View file

@ -19,14 +19,14 @@ abstract class ForumBlockBase extends BlockBase {
*/
public function build() {
$result = $this->buildForumQuery()->execute();
$elements = array();
$elements = [];
if ($node_title_list = node_title_list($result)) {
$elements['forum_list'] = $node_title_list;
$elements['forum_more'] = array(
$elements['forum_more'] = [
'#type' => 'more_link',
'#url' => Url::fromRoute('forum.index'),
'#attributes' => array('title' => $this->t('Read the latest forum topics.')),
);
'#attributes' => ['title' => $this->t('Read the latest forum topics.')],
];
}
return $elements;
}
@ -43,12 +43,12 @@ abstract class ForumBlockBase extends BlockBase {
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'properties' => array(
return [
'properties' => [
'administrative' => TRUE,
),
],
'block_count' => 5,
);
];
}
/**
@ -63,12 +63,12 @@ abstract class ForumBlockBase extends BlockBase {
*/
public function blockForm($form, FormStateInterface $form_state) {
$range = range(2, 20);
$form['block_count'] = array(
$form['block_count'] = [
'#type' => 'select',
'#title' => $this->t('Number of topics'),
'#default_value' => $this->configuration['block_count'],
'#options' => array_combine($range, $range),
);
];
return $form;
}

View file

@ -26,7 +26,7 @@ class ForumLeafConstraintValidator extends ConstraintValidator {
// The forum_container flag must not be set.
if (!empty($item->entity->forum_container->value)) {
$this->context->addViolation($constraint->noLeafMessage, array('%forum' => $item->entity->getName()));
$this->context->addViolation($constraint->noLeafMessage, ['%forum' => $item->entity->getName()]);
}
}

View file

@ -2,6 +2,7 @@
namespace Drupal\forum\Tests\Views;
use Drupal\node\NodeInterface;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
@ -18,19 +19,19 @@ class ForumIntegrationTest extends ViewTestBase {
*
* @var array
*/
public static $modules = array('forum_test_views');
public static $modules = ['forum_test_views'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_forum_index');
public static $testViews = ['test_forum_index'];
protected function setUp() {
parent::setUp();
ViewTestData::createTestViews(get_class($this), array('forum_test_views'));
ViewTestData::createTestViews(get_class($this), ['forum_test_views']);
}
@ -40,25 +41,25 @@ class ForumIntegrationTest extends ViewTestBase {
public function testForumIntegration() {
// Create a forum.
$entity_manager = $this->container->get('entity.manager');
$term = $entity_manager->getStorage('taxonomy_term')->create(array('vid' => 'forums', 'name' => $this->randomMachineName()));
$term = $entity_manager->getStorage('taxonomy_term')->create(['vid' => 'forums', 'name' => $this->randomMachineName()]);
$term->save();
$comment_storage = $entity_manager->getStorage('comment');
// Create some nodes which are part of this forum with some comments.
$nodes = array();
$nodes = [];
for ($i = 0; $i < 3; $i++) {
$node = $this->drupalCreateNode(array('type' => 'forum', 'taxonomy_forums' => array($term->id()), 'sticky' => $i == 0 ? NODE_STICKY : NODE_NOT_STICKY));
$node = $this->drupalCreateNode(['type' => 'forum', 'taxonomy_forums' => [$term->id()], 'sticky' => $i == 0 ? NodeInterface::STICKY : NodeInterface::NOT_STICKY]);
$nodes[] = $node;
}
$account = $this->drupalCreateUser(array('skip comment approval'));
$account = $this->drupalCreateUser(['skip comment approval']);
$this->drupalLogin($account);
$comments = array();
$comments = [];
foreach ($nodes as $index => $node) {
for ($i = 0; $i <= $index; $i++) {
$comment = $comment_storage->create(array('entity_type' => 'node', 'entity_id' => $node->id(), 'field_name' => 'comment_forum'));
$comment = $comment_storage->create(['entity_type' => 'node', 'entity_id' => $node->id(), 'field_name' => 'comment_forum']);
$comment->save();
$comments[$comment->get('entity_id')->target_id][$comment->id()] = $comment;
}
@ -67,27 +68,27 @@ class ForumIntegrationTest extends ViewTestBase {
$view = Views::getView('test_forum_index');
$this->executeView($view);
$expected_result = array();
$expected_result[] = array(
$expected_result = [];
$expected_result[] = [
'nid' => $nodes[0]->id(),
'sticky' => NODE_STICKY,
'sticky' => NodeInterface::STICKY,
'comment_count' => 1.
);
$expected_result[] = array(
];
$expected_result[] = [
'nid' => $nodes[1]->id(),
'sticky' => NODE_NOT_STICKY,
'sticky' => NodeInterface::NOT_STICKY,
'comment_count' => 2.
);
$expected_result[] = array(
];
$expected_result[] = [
'nid' => $nodes[2]->id(),
'sticky' => NODE_NOT_STICKY,
'sticky' => NodeInterface::NOT_STICKY,
'comment_count' => 3.
);
$column_map = array(
];
$column_map = [
'nid' => 'nid',
'forum_index_sticky' => 'sticky',
'forum_index_comment_count' => 'comment_count',
);
];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}

View file

@ -1,24 +1,24 @@
<?php
namespace Drupal\forum\Tests;
namespace Drupal\Tests\forum\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\comment\Entity\Comment;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the forum blocks.
*
* @group forum
*/
class ForumBlockTest extends WebTestBase {
class ForumBlockTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('forum', 'block');
public static $modules = ['forum', 'block'];
/**
* A user with various administrative privileges.
@ -29,14 +29,14 @@ class ForumBlockTest extends WebTestBase {
parent::setUp();
// Create users.
$this->adminUser = $this->drupalCreateUser(array(
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'administer blocks',
'administer nodes',
'create forum content',
'post comments',
'skip comment approval',
));
]);
}
/**
@ -58,7 +58,7 @@ class ForumBlockTest extends WebTestBase {
// We expect all 5 forum topics to appear in the "New forum topics" block.
foreach ($topics as $topic) {
$this->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', array('@topic' => $topic)));
$this->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topic]));
}
// Configure the new forum topics block to only show 2 topics.
@ -69,11 +69,11 @@ class ForumBlockTest extends WebTestBase {
// We expect only the 2 most recent forum topics to appear in the "New forum
// topics" block.
for ($index = 0; $index < 5; $index++) {
if (in_array($index, array(3, 4))) {
$this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "New forum topics" block.', array('@topic' => $topics[$index])));
if (in_array($index, [3, 4])) {
$this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topics[$index]]));
}
else {
$this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "New forum topics" block.', array('@topic' => $topics[$index])));
$this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "New forum topics" block.', ['@topic' => $topics[$index]]));
}
}
}
@ -93,7 +93,7 @@ class ForumBlockTest extends WebTestBase {
// Get the node from the topic title.
$node = $this->drupalGetNodeByTitle($topics[$index]);
$date->modify('+1 minute');
$comment = Comment::create(array(
$comment = Comment::create([
'entity_id' => $node->id(),
'field_name' => 'comment_forum',
'entity_type' => 'node',
@ -101,7 +101,7 @@ class ForumBlockTest extends WebTestBase {
'subject' => $this->randomString(20),
'comment_body' => $this->randomString(256),
'created' => $date->getTimestamp(),
));
]);
$comment->save();
}
@ -116,10 +116,10 @@ class ForumBlockTest extends WebTestBase {
$this->drupalGet('<front>');
for ($index = 0; $index < 10; $index++) {
if ($index < 5) {
$this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "Active forum topics" block.', array('@topic' => $topics[$index])));
$this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "Active forum topics" block.', ['@topic' => $topics[$index]]));
}
else {
$this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "Active forum topics" block.', array('@topic' => $topics[$index])));
$this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "Active forum topics" block.', ['@topic' => $topics[$index]]));
}
}
@ -132,7 +132,7 @@ class ForumBlockTest extends WebTestBase {
// We expect only the 2 forum topics with most recent comments to appear in
// the "Active forum topics" block.
for ($index = 0; $index < 10; $index++) {
if (in_array($index, array(3, 4))) {
if (in_array($index, [3, 4])) {
$this->assertLink($topics[$index], 0, 'Forum topic found in the "Active forum topics" block.');
}
else {
@ -148,7 +148,7 @@ class ForumBlockTest extends WebTestBase {
* The title of the newly generated topic.
*/
protected function createForumTopics($count = 5) {
$topics = array();
$topics = [];
$date = new DrupalDateTime();
$date->modify('-24 hours');
@ -160,17 +160,17 @@ class ForumBlockTest extends WebTestBase {
// changing the date.
$date->modify('+1 minute');
$edit = array(
$edit = [
'title[0][value]' => $title,
'body[0][value]' => $body,
// Forum posts are ordered by timestamp, so force a unique timestamp by
// adding the index.
'created[0][value][date]' => $date->format('Y-m-d'),
'created[0][value][time]' => $date->format('H:i:s'),
);
];
// Create the forum topic, preselecting the forum ID via a URL parameter.
$this->drupalPostForm('node/add/forum', $edit, t('Save and publish'), array('query' => array('forum_id' => 1)));
$this->drupalPostForm('node/add/forum', $edit, t('Save and publish'), ['query' => ['forum_id' => 1]]);
$topics[] = $title;
}

View file

@ -1,22 +1,22 @@
<?php
namespace Drupal\forum\Tests;
namespace Drupal\Tests\forum\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the forum index listing.
*
* @group forum
*/
class ForumIndexTest extends WebTestBase {
class ForumIndexTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy', 'comment', 'forum');
public static $modules = ['taxonomy', 'comment', 'forum'];
protected function setUp() {
parent::setUp();
@ -29,21 +29,21 @@ class ForumIndexTest extends WebTestBase {
/**
* Tests the forum index for published and unpublished nodes.
*/
function testForumIndexStatus() {
public function testForumIndexStatus() {
// The forum ID to use.
$tid = 1;
// Create a test node.
$title = $this->randomMachineName(20);
$edit = array(
$edit = [
'title[0][value]' => $title,
'body[0][value]' => $this->randomMachineName(200),
);
];
// Create the forum topic, preselecting the forum ID via a URL parameter.
$this->drupalGet("forum/$tid");
$this->clickLink(t('Add new @node_type', array('@node_type' => 'Forum topic')));
$this->assertUrl('node/add/forum', array('query' => array('forum_id' => $tid)));
$this->clickLink(t('Add new @node_type', ['@node_type' => 'Forum topic']));
$this->assertUrl('node/add/forum', ['query' => ['forum_id' => $tid]]);
$this->drupalPostForm(NULL, $edit, t('Save and publish'));
// Check that the node exists in the database.
@ -51,11 +51,11 @@ class ForumIndexTest extends WebTestBase {
$this->assertTrue(!empty($node), 'New forum node found in database.');
// Create a child forum.
$edit = array(
$edit = [
'name[0][value]' => $this->randomMachineName(20),
'description[0][value]' => $this->randomMachineName(200),
'parent[0]' => $tid,
);
];
$this->drupalPostForm('admin/structure/forum/add/forum', $edit, t('Save'));
$tid_child = $tid + 1;
@ -71,7 +71,7 @@ class ForumIndexTest extends WebTestBase {
// Unpublish the node.
$this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish'));
$this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and unpublish'));
$this->drupalGet('node/' . $node->id());
$this->assertText(t('Access denied'), 'Unpublished node is no longer accessible.');

View file

@ -1,8 +1,8 @@
<?php
namespace Drupal\forum\Tests;
namespace Drupal\Tests\forum\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\node\Entity\NodeType;
/**
@ -10,14 +10,14 @@ use Drupal\node\Entity\NodeType;
*
* @group forum
*/
class ForumNodeAccessTest extends WebTestBase {
class ForumNodeAccessTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block');
public static $modules = ['node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block'];
protected function setUp() {
parent::setUp();
@ -32,32 +32,32 @@ class ForumNodeAccessTest extends WebTestBase {
* Adds both active forum topics and new forum topics blocks to the sidebar.
* Tests to ensure private node/public node access is respected on blocks.
*/
function testForumNodeAccess() {
public function testForumNodeAccess() {
// Create some users.
$access_user = $this->drupalCreateUser(array('node test view'));
$access_user = $this->drupalCreateUser(['node test view']);
$no_access_user = $this->drupalCreateUser();
$admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules', 'administer blocks', 'create forum content'));
$admin_user = $this->drupalCreateUser(['access administration pages', 'administer modules', 'administer blocks', 'create forum content']);
$this->drupalLogin($admin_user);
// Create a private node.
$private_node_title = $this->randomMachineName(20);
$edit = array(
$edit = [
'title[0][value]' => $private_node_title,
'body[0][value]' => $this->randomMachineName(200),
'private[0][value]' => TRUE,
);
$this->drupalPostForm('node/add/forum', $edit, t('Save'), array('query' => array('forum_id' => 1)));
];
$this->drupalPostForm('node/add/forum', $edit, t('Save'), ['query' => ['forum_id' => 1]]);
$private_node = $this->drupalGetNodeByTitle($private_node_title);
$this->assertTrue(!empty($private_node), 'New private forum node found in database.');
// Create a public node.
$public_node_title = $this->randomMachineName(20);
$edit = array(
$edit = [
'title[0][value]' => $public_node_title,
'body[0][value]' => $this->randomMachineName(200),
);
$this->drupalPostForm('node/add/forum', $edit, t('Save'), array('query' => array('forum_id' => 1)));
];
$this->drupalPostForm('node/add/forum', $edit, t('Save'), ['query' => ['forum_id' => 1]]);
$public_node = $this->drupalGetNodeByTitle($public_node_title);
$this->assertTrue(!empty($public_node), 'New public forum node found in database.');

View file

@ -1,14 +1,14 @@
<?php
namespace Drupal\forum\Tests;
namespace Drupal\Tests\forum\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Url;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\BrowserTestBase;
/**
* Tests for forum.module.
@ -18,14 +18,14 @@ use Drupal\taxonomy\Entity\Vocabulary;
*
* @group forum
*/
class ForumTest extends WebTestBase {
class ForumTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy', 'comment', 'forum', 'node', 'block', 'menu_ui', 'help');
public static $modules = ['taxonomy', 'comment', 'forum', 'node', 'block', 'menu_ui', 'help'];
/**
* A user with various administrative privileges.
@ -81,7 +81,7 @@ class ForumTest extends WebTestBase {
$this->drupalPlaceBlock('page_title_block');
// Create users.
$this->adminUser = $this->drupalCreateUser(array(
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'administer modules',
'administer blocks',
@ -90,34 +90,34 @@ class ForumTest extends WebTestBase {
'administer taxonomy',
'create forum content',
'access comments',
));
$this->editAnyTopicsUser = $this->drupalCreateUser(array(
]);
$this->editAnyTopicsUser = $this->drupalCreateUser([
'access administration pages',
'create forum content',
'edit any forum content',
'delete any forum content',
));
$this->editOwnTopicsUser = $this->drupalCreateUser(array(
]);
$this->editOwnTopicsUser = $this->drupalCreateUser([
'create forum content',
'edit own forum content',
'delete own forum content',
));
]);
$this->webUser = $this->drupalCreateUser();
$this->postCommentUser = $this->drupalCreateUser(array(
$this->postCommentUser = $this->drupalCreateUser([
'administer content types',
'create forum content',
'post comments',
'skip comment approval',
'access comments',
));
$this->drupalPlaceBlock('help_block', array('region' => 'help'));
]);
$this->drupalPlaceBlock('help_block', ['region' => 'help']);
$this->drupalPlaceBlock('local_actions_block');
}
/**
* Tests forum functionality through the admin and user interfaces.
*/
function testForum() {
public function testForum() {
//Check that the basic forum install creates a default forum topic
$this->drupalGet('/forum');
// Look for the "General discussion" default forum
@ -188,37 +188,37 @@ class ForumTest extends WebTestBase {
$this->drupalGet('forum');
// Verify row for testing forum.
$forum_arg = array(':forum' => 'forum-list-' . $this->forum['tid']);
$forum_arg = [':forum' => 'forum-list-' . $this->forum['tid']];
// Topics cell contains number of topics and number of unread topics.
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="forum__topics"]', $forum_arg);
$topics = $this->xpath($xpath);
$topics = trim($topics[0]);
$this->assertEqual($topics, '6', 'Number of topics found.');
$topics = trim($topics[0]->getText());
// The extracted text contains the number of topics (6) and new posts
// (also 6) in this table cell.
$this->assertEquals('6 6 new posts in forum ' . $this->forum['name'], $topics, 'Number of topics found.');
// Verify the number of unread topics.
$unread_topics = $this->container->get('forum_manager')->unreadTopics($this->forum['tid'], $this->editAnyTopicsUser->id());
$unread_topics = \Drupal::translation()->formatPlural($unread_topics, '1 new post', '@count new posts');
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="forum__topics"]//a', $forum_arg);
$this->assertFieldByXPath($xpath, $unread_topics, 'Number of unread topics found.');
$elements = $this->xpath('//tr[@id=:forum]//td[@class="forum__topics"]//a', $forum_arg);
$this->assertStringStartsWith('6 new posts', $elements[0]->getText(), 'Number of unread topics found.');
// Verify that the forum name is in the unread topics text.
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//em[@class="placeholder"]', $forum_arg);
$this->assertFieldByXpath($xpath, $this->forum['name'], 'Forum name found in unread topics text.');
$elements = $this->xpath('//tr[@id=:forum]//em[@class="placeholder"]', $forum_arg);
$this->assertContains($this->forum['name'], $elements[0]->getText(), 'Forum name found in unread topics text.');
// Verify total number of posts in forum.
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="forum__posts"]', $forum_arg);
$this->assertFieldByXPath($xpath, '6', 'Number of posts found.');
$elements = $this->xpath('//tr[@id=:forum]//td[@class="forum__posts"]', $forum_arg);
$this->assertEquals('6', $elements[0]->getText(), 'Number of posts found.');
// Test loading multiple forum nodes on the front page.
$this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content', 'post comments')));
$this->drupalPostForm('admin/structure/types/manage/forum', array('options[promote]' => 'promote'), t('Save content type'));
$this->drupalLogin($this->drupalCreateUser(['administer content types', 'create forum content', 'post comments']));
$this->drupalPostForm('admin/structure/types/manage/forum', ['options[promote]' => 'promote'], t('Save content type'));
$this->createForumTopic($this->forum, FALSE);
$this->createForumTopic($this->forum, FALSE);
$this->drupalGet('node');
// Test adding a comment to a forum topic.
$node = $this->createForumTopic($this->forum, FALSE);
$edit = array();
$edit = [];
$edit['comment_body[0][value]'] = $this->randomMachineName();
$this->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
$this->assertResponse(200);
@ -226,7 +226,7 @@ class ForumTest extends WebTestBase {
// Test editing a forum topic that has a comment.
$this->drupalLogin($this->editAnyTopicsUser);
$this->drupalGet('forum/' . $this->forum['tid']);
$this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save'));
$this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save'));
$this->assertResponse(200);
// Test the root forum page title change.
@ -251,7 +251,7 @@ class ForumTest extends WebTestBase {
* Verifies that forum nodes are not created without choosing "forum" from the
* select list.
*/
function testAddOrphanTopic() {
public function testAddOrphanTopic() {
// Must remove forum topics to test creating orphan topics.
$vid = $this->config('forum.settings')->get('vocabulary');
$tids = \Drupal::entityQuery('taxonomy_term')
@ -260,7 +260,7 @@ class ForumTest extends WebTestBase {
entity_delete_multiple('taxonomy_term', $tids);
// Create an orphan forum item.
$edit = array();
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName(10);
$edit['body[0][value]'] = $this->randomMachineName(120);
$this->drupalLogin($this->adminUser);
@ -270,7 +270,7 @@ class ForumTest extends WebTestBase {
$this->assertEqual(0, $nid_count, 'A forum node was not created when missing a forum vocabulary.');
// Reset the defaults for future tests.
\Drupal::service('module_installer')->install(array('forum'));
\Drupal::service('module_installer')->install(['forum']);
}
/**
@ -284,7 +284,7 @@ class ForumTest extends WebTestBase {
$this->drupalLogin($user);
// Add forum to the Tools menu.
$edit = array();
$edit = [];
$this->drupalPostForm('admin/structure/menu/manage/tools', $edit, t('Save'));
$this->assertResponse(200);
@ -313,7 +313,7 @@ class ForumTest extends WebTestBase {
// Create second forum in container, destined to be deleted below.
$delete_forum = $this->createForum('forum', $this->forumContainer['tid']);
// Save forum overview.
$this->drupalPostForm('admin/structure/forum/', array(), t('Save'));
$this->drupalPostForm('admin/structure/forum/', [], t('Save'));
$this->assertRaw(t('The configuration options have been saved.'));
// Delete this second forum.
$this->deleteForum($delete_forum['tid']);
@ -322,8 +322,8 @@ class ForumTest extends WebTestBase {
// Test vocabulary form alterations.
$this->drupalGet('admin/structure/taxonomy/manage/forums');
$this->assertFieldByName('op', t('Save'), 'Save button found.');
$this->assertNoFieldByName('op', t('Delete'), 'Delete button not found.');
$this->assertSession()->buttonExists('Save');
$this->assertSession()->buttonNotExists('Delete');
// Test term edit form alterations.
$this->drupalGet('taxonomy/term/' . $this->forumContainer['tid'] . '/edit');
@ -343,7 +343,7 @@ class ForumTest extends WebTestBase {
$vocabulary->save();
// Test tags vocabulary form is not affected.
$this->drupalGet('admin/structure/taxonomy/manage/tags');
$this->assertFieldByName('op', t('Save'), 'Save button found.');
$this->assertSession()->buttonExists('Save');
$this->assertLink(t('Delete'));
// Test tags vocabulary term form is not affected.
$this->drupalGet('admin/structure/taxonomy/manage/tags/add');
@ -356,21 +356,21 @@ class ForumTest extends WebTestBase {
/**
* Edits the forum taxonomy.
*/
function editForumVocabulary() {
public function editForumVocabulary() {
// Backup forum taxonomy.
$vid = $this->config('forum.settings')->get('vocabulary');
$original_vocabulary = Vocabulary::load($vid);
// Generate a random name and description.
$edit = array(
$edit = [
'name' => $this->randomMachineName(10),
'description' => $this->randomMachineName(100),
);
];
// Edit the vocabulary.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $original_vocabulary->id(), $edit, t('Save'));
$this->assertResponse(200);
$this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary was edited');
$this->assertRaw(t('Updated vocabulary %name.', ['%name' => $edit['name']]), 'Vocabulary was edited');
// Grab the newly edited vocabulary.
$current_vocabulary = Vocabulary::load($vid);
@ -399,17 +399,17 @@ class ForumTest extends WebTestBase {
* @return \Drupal\Core\Database\StatementInterface
* The created taxonomy term data.
*/
function createForum($type, $parent = 0) {
public function createForum($type, $parent = 0) {
// Generate a random name/description.
$name = $this->randomMachineName(10);
$description = $this->randomMachineName(100);
$edit = array(
$edit = [
'name[0][value]' => $name,
'description[0][value]' => $description,
'parent[0]' => $parent,
'weight' => '0',
);
];
// Create forum.
$this->drupalPostForm('admin/structure/forum/add/' . $type, $edit, t('Save'));
@ -418,22 +418,22 @@ class ForumTest extends WebTestBase {
$this->assertText(
t(
'Created new @type @term.',
array('@term' => $name, '@type' => t($type))
['@term' => $name, '@type' => t($type)]
),
format_string('@type was created', array('@type' => ucfirst($type)))
format_string('@type was created', ['@type' => ucfirst($type)])
);
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
// Verify forum.
$term = db_query("SELECT * FROM {taxonomy_term_field_data} t WHERE t.vid = :vid AND t.name = :name AND t.description__value = :desc AND t.default_langcode = 1", array(':vid' => $this->config('forum.settings')->get('vocabulary'), ':name' => $name, ':desc' => $description))->fetchAssoc();
$term = db_query("SELECT * FROM {taxonomy_term_field_data} t WHERE t.vid = :vid AND t.name = :name AND t.description__value = :desc AND t.default_langcode = 1", [':vid' => $this->config('forum.settings')->get('vocabulary'), ':name' => $name, ':desc' => $description])->fetchAssoc();
$this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
// Verify forum hierarchy.
$tid = $term['tid'];
$parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(':tid' => $tid))->fetchField();
$parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", [':tid' => $tid])->fetchField();
$this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
$forum = $this->container->get('entity.manager')->getStorage('taxonomy_term')->load($tid);
@ -447,14 +447,14 @@ class ForumTest extends WebTestBase {
* @param int $tid
* The forum ID.
*/
function deleteForum($tid) {
public function deleteForum($tid) {
// Delete the forum.
$this->drupalGet('admin/structure/forum/edit/forum/' . $tid);
$this->clickLink(t('Delete'));
$this->assertText('Are you sure you want to delete the forum');
$this->assertNoText('Add forum');
$this->assertNoText('Add forum container');
$this->drupalPostForm(NULL, array(), t('Delete'));
$this->drupalPostForm(NULL, [], t('Delete'));
// Assert that the forum no longer exists.
$this->drupalGet('forum/' . $tid);
@ -483,7 +483,7 @@ class ForumTest extends WebTestBase {
/**
* Tests a forum with a new post displays properly.
*/
function testForumWithNewPost() {
public function testForumWithNewPost() {
// Log in as the first user.
$this->drupalLogin($this->adminUser);
// Create a forum container.
@ -496,7 +496,7 @@ class ForumTest extends WebTestBase {
// Log in as a second user.
$this->drupalLogin($this->postCommentUser);
// Post a reply to the topic.
$edit = array();
$edit = [];
$edit['subject[0][value]'] = $this->randomMachineName();
$edit['comment_body[0][value]'] = $this->randomMachineName();
$this->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
@ -528,38 +528,38 @@ class ForumTest extends WebTestBase {
* @return object
* The created topic node.
*/
function createForumTopic($forum, $container = FALSE) {
public function createForumTopic($forum, $container = FALSE) {
// Generate a random subject/body.
$title = $this->randomMachineName(20);
$body = $this->randomMachineName(200);
$edit = array(
$edit = [
'title[0][value]' => $title,
'body[0][value]' => $body,
);
];
$tid = $forum['tid'];
// Create the forum topic, preselecting the forum ID via a URL parameter.
$this->drupalPostForm('node/add/forum', $edit, t('Save'), array('query' => array('forum_id' => $tid)));
$this->drupalPostForm('node/add/forum', $edit, t('Save'), ['query' => ['forum_id' => $tid]]);
$type = t('Forum topic');
if ($container) {
$this->assertNoText(t('@type @title has been created.', array('@type' => $type, '@title' => $title)), 'Forum topic was not created');
$this->assertRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), 'Error message was shown');
$this->assertNoText(t('@type @title has been created.', ['@type' => $type, '@title' => $title]), 'Forum topic was not created');
$this->assertRaw(t('The item %title is a forum container, not a forum.', ['%title' => $forum['name']]), 'Error message was shown');
return;
}
else {
$this->assertText(t('@type @title has been created.', array('@type' => $type, '@title' => $title)), 'Forum topic was created');
$this->assertNoRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), 'No error message was shown');
$this->assertText(t('@type @title has been created.', ['@type' => $type, '@title' => $title]), 'Forum topic was created');
$this->assertNoRaw(t('The item %title is a forum container, not a forum.', ['%title' => $forum['name']]), 'No error message was shown');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
}
// Retrieve node object, ensure that the topic was created and in the proper forum.
$node = $this->drupalGetNodeByTitle($title);
$this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title)));
$this->assertTrue($node != NULL, format_string('Node @title was loaded', ['@title' => $title]));
$this->assertEqual($node->taxonomy_forums->target_id, $tid, 'Saved forum topic was in the expected forum');
// View forum topic.
@ -602,16 +602,16 @@ class ForumTest extends WebTestBase {
$this->drupalGet('node/' . $node->id());
$this->assertResponse(200);
$this->assertTitle($node->label() . ' | Drupal', 'Forum node was displayed');
$breadcrumb_build = array(
$breadcrumb_build = [
Link::createFromRoute(t('Home'), '<front>'),
Link::createFromRoute(t('Forums'), 'forum.index'),
Link::createFromRoute($this->forumContainer['name'], 'forum.page', array('taxonomy_term' => $this->forumContainer['tid'])),
Link::createFromRoute($this->forum['name'], 'forum.page', array('taxonomy_term' => $this->forum['tid'])),
);
$breadcrumb = array(
Link::createFromRoute($this->forumContainer['name'], 'forum.page', ['taxonomy_term' => $this->forumContainer['tid']]),
Link::createFromRoute($this->forum['name'], 'forum.page', ['taxonomy_term' => $this->forum['tid']]),
];
$breadcrumb = [
'#theme' => 'breadcrumb',
'#links' => $breadcrumb_build,
);
];
$this->assertRaw(\Drupal::service('renderer')->renderRoot($breadcrumb), 'Breadcrumbs were displayed');
// View forum edit node.
@ -623,26 +623,26 @@ class ForumTest extends WebTestBase {
if ($response == 200) {
// Edit forum node (including moving it to another forum).
$edit = array();
$edit = [];
$edit['title[0][value]'] = 'node/' . $node->id();
$edit['body[0][value]'] = $this->randomMachineName(256);
// Assume the topic is initially associated with $forum.
$edit['taxonomy_forums'] = $this->rootForum['tid'];
$edit['shadow'] = TRUE;
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->assertText(t('Forum topic @title has been updated.', array('@title' => $edit['title[0][value]'])), 'Forum node was edited');
$this->assertText(t('Forum topic @title has been updated.', ['@title' => $edit['title[0][value]']]), 'Forum node was edited');
// Verify topic was moved to a different forum.
$forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array(
$forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", [
':nid' => $node->id(),
':vid' => $node->getRevisionId(),
))->fetchField();
])->fetchField();
$this->assertTrue($forum_tid == $this->rootForum['tid'], 'The forum topic is linked to a different forum');
// Delete forum node.
$this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete'));
$this->drupalPostForm('node/' . $node->id() . '/delete', [], t('Delete'));
$this->assertResponse($response);
$this->assertRaw(t('Forum topic %title has been deleted.', array('%title' => $edit['title[0][value]'])), 'Forum node was deleted');
$this->assertRaw(t('Forum topic %title has been deleted.', ['%title' => $edit['title[0][value]']]), 'Forum node was deleted');
}
}
@ -660,18 +660,18 @@ class ForumTest extends WebTestBase {
$this->assertResponse(200);
$this->assertTitle($forum['name'] . ' | Drupal');
$breadcrumb_build = array(
$breadcrumb_build = [
Link::createFromRoute(t('Home'), '<front>'),
Link::createFromRoute(t('Forums'), 'forum.index'),
);
];
if (isset($parent)) {
$breadcrumb_build[] = Link::createFromRoute($parent['name'], 'forum.page', array('taxonomy_term' => $parent['tid']));
$breadcrumb_build[] = Link::createFromRoute($parent['name'], 'forum.page', ['taxonomy_term' => $parent['tid']]);
}
$breadcrumb = array(
$breadcrumb = [
'#theme' => 'breadcrumb',
'#links' => $breadcrumb_build,
);
];
$this->assertRaw(\Drupal::service('renderer')->renderRoot($breadcrumb), 'Breadcrumbs were displayed');
}
@ -679,7 +679,7 @@ class ForumTest extends WebTestBase {
* Generates forum topics.
*/
private function generateForumTopics() {
$this->nids = array();
$this->nids = [];
for ($i = 0; $i < 5; $i++) {
$node = $this->createForumTopic($this->forum, FALSE);
$this->nids[] = $node->id();

View file

@ -1,27 +1,27 @@
<?php
namespace Drupal\forum\Tests;
namespace Drupal\Tests\forum\Functional;
use Drupal\comment\CommentInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\BrowserTestBase;
/**
* Tests forum module uninstallation.
*
* @group forum
*/
class ForumUninstallTest extends WebTestBase {
class ForumUninstallTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('forum');
public static $modules = ['forum'];
/**
* Tests if forum module uninstallation properly deletes the field.
@ -37,21 +37,21 @@ class ForumUninstallTest extends WebTestBase {
'name' => t('A term'),
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
'description' => '',
'parent' => array(0),
'parent' => [0],
'vid' => 'forums',
'forum_container' => 0,
]);
$term->save();
// Create a forum node.
$node = $this->drupalCreateNode(array(
$node = $this->drupalCreateNode([
'title' => 'A forum post',
'type' => 'forum',
'taxonomy_forums' => array(array('target_id' => $term->id())),
));
'taxonomy_forums' => [['target_id' => $term->id()]],
]);
// Create at least one comment against the forum node.
$comment = Comment::create(array(
$comment = Comment::create([
'entity_id' => $node->nid->value,
'entity_type' => 'node',
'field_name' => 'comment_forum',
@ -60,22 +60,22 @@ class ForumUninstallTest extends WebTestBase {
'status' => CommentInterface::PUBLISHED,
'subject' => $this->randomMachineName(),
'hostname' => '127.0.0.1',
));
]);
$comment->save();
// Attempt to uninstall forum.
$this->drupalGet('admin/modules/uninstall');
// Assert forum is required.
$this->assertNoFieldByName('uninstall[forum]');
$this->assertSession()->fieldDisabled('uninstall[forum]');
$this->assertText('To uninstall Forum, first delete all Forum content');
// Delete the node.
$this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete'));
$this->drupalPostForm('node/' . $node->id() . '/delete', [], t('Delete'));
// Attempt to uninstall forum.
$this->drupalGet('admin/modules/uninstall');
// Assert forum is still required.
$this->assertNoFieldByName('uninstall[forum]');
$this->assertSession()->fieldDisabled('uninstall[forum]');
$this->assertText('To uninstall Forum, first delete all Forums terms');
// Delete any forum terms.
@ -93,9 +93,9 @@ class ForumUninstallTest extends WebTestBase {
$this->drupalGet('admin/modules/uninstall');
// Assert forum is no longer required.
$this->assertFieldByName('uninstall[forum]');
$this->drupalPostForm('admin/modules/uninstall', array(
$this->drupalPostForm('admin/modules/uninstall', [
'uninstall[forum]' => 1,
), t('Uninstall'));
], t('Uninstall'));
$this->drupalPostForm(NULL, [], t('Uninstall'));
// Check that the field is now deleted.
@ -104,21 +104,21 @@ class ForumUninstallTest extends WebTestBase {
// Check that a node type with a machine name of forum can be created after
// uninstalling the forum module and the node type is not locked.
$edit = array(
$edit = [
'name' => 'Forum',
'title_label' => 'title for forum',
'type' => 'forum',
);
];
$this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type'));
$this->assertTrue((bool) NodeType::load('forum'), 'Node type with machine forum created.');
$this->drupalGet('admin/structure/types/manage/forum');
$this->clickLink(t('Delete'));
$this->drupalPostForm(NULL, array(), t('Delete'));
$this->drupalPostForm(NULL, [], t('Delete'));
$this->assertResponse(200);
$this->assertFalse((bool) NodeType::load('forum'), 'Node type with machine forum deleted.');
// Double check everything by reinstalling the forum module again.
$this->drupalPostForm('admin/modules', ['modules[Core][forum][enable]' => 1], 'Install');
$this->drupalPostForm('admin/modules', ['modules[forum][enable]' => 1], 'Install');
$this->assertText('Module Forum has been enabled.');
}
@ -137,14 +137,14 @@ class ForumUninstallTest extends WebTestBase {
// Delete all terms in the Forums vocabulary. Uninstalling the forum module
// will fail unless this is done.
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => 'forums'));
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => 'forums']);
foreach ($terms as $term) {
$term->delete();
}
// Ensure that uninstallation succeeds even if the field has already been
// deleted manually beforehand.
$this->container->get('module_installer')->uninstall(array('forum'));
$this->container->get('module_installer')->uninstall(['forum']);
}
}

View file

@ -2,7 +2,7 @@
namespace Drupal\Tests\forum\Kernel\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
@ -17,7 +17,7 @@ class MigrateForumConfigsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('comment', 'forum', 'taxonomy');
public static $modules = ['comment', 'forum', 'taxonomy'];
/**
* {@inheritdoc}

View file

@ -37,9 +37,9 @@ class ForumBreadcrumbBuilderBaseTest extends UnitTestCase {
// Make some test doubles.
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$config_factory = $this->getConfigFactoryStub(
array(
'forum.settings' => array('IAmATestKey' => 'IAmATestValue'),
)
[
'forum.settings' => ['IAmATestKey' => 'IAmATestValue'],
]
);
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
$translation_manager = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
@ -48,20 +48,20 @@ class ForumBreadcrumbBuilderBaseTest extends UnitTestCase {
$builder = $this->getMockForAbstractClass(
'Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase',
// Constructor array.
array(
[
$entity_manager,
$config_factory,
$forum_manager,
$translation_manager,
)
]
);
// Reflect upon our properties, except for config which is a special case.
$property_names = array(
$property_names = [
'entityManager' => $entity_manager,
'forumManager' => $forum_manager,
'stringTranslation' => $translation_manager,
);
];
foreach ($property_names as $property_name => $property_value) {
$this->assertAttributeEquals(
$property_value, $property_name, $builder
@ -103,37 +103,37 @@ class ForumBreadcrumbBuilderBaseTest extends UnitTestCase {
$vocab_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$vocab_storage->expects($this->any())
->method('load')
->will($this->returnValueMap(array(
array('forums', $prophecy->reveal()),
)));
->will($this->returnValueMap([
['forums', $prophecy->reveal()],
]));
$entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManagerInterface')
->disableOriginalConstructor()
->getMock();
$entity_manager->expects($this->any())
->method('getStorage')
->will($this->returnValueMap(array(
array('taxonomy_vocabulary', $vocab_storage),
)));
->will($this->returnValueMap([
['taxonomy_vocabulary', $vocab_storage],
]));
$config_factory = $this->getConfigFactoryStub(
array(
'forum.settings' => array(
[
'forum.settings' => [
'vocabulary' => 'forums',
),
)
],
]
);
// Build a breadcrumb builder to test.
$breadcrumb_builder = $this->getMockForAbstractClass(
'Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase',
// Constructor array.
array(
[
$entity_manager,
$config_factory,
$forum_manager,
$translation_manager,
)
]
);
// Add a translation manager for t().
@ -144,10 +144,10 @@ class ForumBreadcrumbBuilderBaseTest extends UnitTestCase {
$route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
// Expected result set.
$expected = array(
$expected = [
Link::createFromRoute('Home', '<front>'),
Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index'),
);
];
// And finally, the test.
$breadcrumb = $breadcrumb_builder->build($route_match);

View file

@ -41,21 +41,21 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
* @dataProvider providerTestApplies
* @covers ::applies
*/
public function testApplies($expected, $route_name = NULL, $parameter_map = array()) {
public function testApplies($expected, $route_name = NULL, $parameter_map = []) {
// Make some test doubles.
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$config_factory = $this->getConfigFactoryStub(array());
$config_factory = $this->getConfigFactoryStub([]);
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
$translation_manager = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
// Make an object to test.
$builder = $this->getMockBuilder('Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder')
->setConstructorArgs(array(
->setConstructorArgs([
$entity_manager,
$config_factory,
$forum_manager,
$translation_manager,
))
])
->setMethods(NULL)
->getMock();
@ -84,29 +84,29 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
->disableOriginalConstructor()
->getMock();
return array(
array(
return [
[
FALSE,
),
array(
],
[
FALSE,
'NOT.forum.page',
),
array(
],
[
FALSE,
'forum.page',
),
array(
],
[
TRUE,
'forum.page',
array(array('taxonomy_term', 'anything')),
),
array(
[['taxonomy_term', 'anything']],
],
[
TRUE,
'forum.page',
array(array('taxonomy_term', $mock_term)),
),
);
[['taxonomy_term', $mock_term]],
],
];
}
/**
@ -141,10 +141,10 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
$forum_manager->expects($this->at(0))
->method('getParents')
->will($this->returnValue(array($term1)));
->will($this->returnValue([$term1]));
$forum_manager->expects($this->at(1))
->method('getParents')
->will($this->returnValue(array($term1, $term2)));
->will($this->returnValue([$term1, $term2]));
// The root forum.
$prophecy = $this->prophesize('Drupal\taxonomy\VocabularyInterface');
@ -156,35 +156,35 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
$vocab_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$vocab_storage->expects($this->any())
->method('load')
->will($this->returnValueMap(array(
array('forums', $prophecy->reveal()),
)));
->will($this->returnValueMap([
['forums', $prophecy->reveal()],
]));
$entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManagerInterface')
->disableOriginalConstructor()
->getMock();
$entity_manager->expects($this->any())
->method('getStorage')
->will($this->returnValueMap(array(
array('taxonomy_vocabulary', $vocab_storage),
)));
->will($this->returnValueMap([
['taxonomy_vocabulary', $vocab_storage],
]));
$config_factory = $this->getConfigFactoryStub(
array(
'forum.settings' => array(
[
'forum.settings' => [
'vocabulary' => 'forums',
),
)
],
]
);
// Build a breadcrumb builder to test.
$breadcrumb_builder = $this->getMock(
'Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder', NULL, array(
'Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder', NULL, [
$entity_manager,
$config_factory,
$forum_manager,
$translation_manager,
)
]
);
// Add a translation manager for t().
@ -208,11 +208,11 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
->will($this->returnValue($forum_listing));
// First test.
$expected1 = array(
$expected1 = [
Link::createFromRoute('Home', '<front>'),
Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index'),
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
);
Link::createFromRoute('Something', 'forum.page', ['taxonomy_term' => 1]),
];
$breadcrumb = $breadcrumb_builder->build($route_match);
$this->assertEquals($expected1, $breadcrumb->getLinks());
$this->assertEquals(['route'], $breadcrumb->getCacheContexts());
@ -220,12 +220,12 @@ class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
// Second test.
$expected2 = array(
$expected2 = [
Link::createFromRoute('Home', '<front>'),
Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index'),
Link::createFromRoute('Something else', 'forum.page', array('taxonomy_term' => 2)),
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
);
Link::createFromRoute('Something else', 'forum.page', ['taxonomy_term' => 2]),
Link::createFromRoute('Something', 'forum.page', ['taxonomy_term' => 1]),
];
$breadcrumb = $breadcrumb_builder->build($route_match);
$this->assertEquals($expected2, $breadcrumb->getLinks());
$this->assertEquals(['route'], $breadcrumb->getCacheContexts());

View file

@ -41,10 +41,10 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
* @dataProvider providerTestApplies
* @covers ::applies
*/
public function testApplies($expected, $route_name = NULL, $parameter_map = array()) {
public function testApplies($expected, $route_name = NULL, $parameter_map = []) {
// Make some test doubles.
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$config_factory = $this->getConfigFactoryStub(array());
$config_factory = $this->getConfigFactoryStub([]);
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
$forum_manager->expects($this->any())
@ -56,12 +56,12 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
// Make an object to test.
$builder = $this->getMockBuilder('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder')
->setConstructorArgs(
array(
[
$entity_manager,
$config_factory,
$forum_manager,
$translation_manager,
)
]
)
->setMethods(NULL)
->getMock();
@ -93,29 +93,29 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
->disableOriginalConstructor()
->getMock();
return array(
array(
return [
[
FALSE,
),
array(
],
[
FALSE,
'NOT.entity.node.canonical',
),
array(
],
[
FALSE,
'entity.node.canonical',
),
array(
],
[
FALSE,
'entity.node.canonical',
array(array('node', NULL)),
),
array(
[['node', NULL]],
],
[
TRUE,
'entity.node.canonical',
array(array('node', $mock_node)),
),
);
[['node', $mock_node]],
],
];
}
/**
@ -151,10 +151,10 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
->getMock();
$forum_manager->expects($this->at(0))
->method('getParents')
->will($this->returnValue(array($term1)));
->will($this->returnValue([$term1]));
$forum_manager->expects($this->at(1))
->method('getParents')
->will($this->returnValue(array($term1, $term2)));
->will($this->returnValue([$term1, $term2]));
$prophecy = $this->prophesize('Drupal\taxonomy\VocabularyInterface');
$prophecy->label()->willReturn('Forums');
@ -165,35 +165,35 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
$vocab_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$vocab_storage->expects($this->any())
->method('load')
->will($this->returnValueMap(array(
array('forums', $prophecy->reveal()),
)));
->will($this->returnValueMap([
['forums', $prophecy->reveal()],
]));
$entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManagerInterface')
->disableOriginalConstructor()
->getMock();
$entity_manager->expects($this->any())
->method('getStorage')
->will($this->returnValueMap(array(
array('taxonomy_vocabulary', $vocab_storage),
)));
->will($this->returnValueMap([
['taxonomy_vocabulary', $vocab_storage],
]));
$config_factory = $this->getConfigFactoryStub(
array(
'forum.settings' => array(
[
'forum.settings' => [
'vocabulary' => 'forums',
),
)
],
]
);
// Build a breadcrumb builder to test.
$breadcrumb_builder = $this->getMock(
'Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', NULL, array(
'Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', NULL, [
$entity_manager,
$config_factory,
$forum_manager,
$translation_manager,
)
]
);
// Add a translation manager for t().
@ -215,11 +215,11 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
->will($this->returnValue($forum_node));
// First test.
$expected1 = array(
$expected1 = [
Link::createFromRoute('Home', '<front>'),
Link::createFromRoute('Forums', 'forum.index'),
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
);
Link::createFromRoute('Something', 'forum.page', ['taxonomy_term' => 1]),
];
$breadcrumb = $breadcrumb_builder->build($route_match);
$this->assertEquals($expected1, $breadcrumb->getLinks());
$this->assertEquals(['route'], $breadcrumb->getCacheContexts());
@ -227,12 +227,12 @@ class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
// Second test.
$expected2 = array(
$expected2 = [
Link::createFromRoute('Home', '<front>'),
Link::createFromRoute('Forums', 'forum.index'),
Link::createFromRoute('Something else', 'forum.page', array('taxonomy_term' => 2)),
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
);
Link::createFromRoute('Something else', 'forum.page', ['taxonomy_term' => 2]),
Link::createFromRoute('Something', 'forum.page', ['taxonomy_term' => 1]),
];
$breadcrumb = $breadcrumb_builder->build($route_match);
$this->assertEquals($expected2, $breadcrumb->getLinks());
$this->assertEquals(['route'], $breadcrumb->getCacheContexts());

View file

@ -57,17 +57,17 @@ class ForumManagerTest extends UnitTestCase {
->disableOriginalConstructor()
->getMock();
$manager = $this->getMock('\Drupal\forum\ForumManager', array('getChildren'), array(
$manager = $this->getMock('\Drupal\forum\ForumManager', ['getChildren'], [
$config_factory,
$entity_manager,
$connection,
$translation_manager,
$comment_manager,
));
]);
$manager->expects($this->once())
->method('getChildren')
->will($this->returnValue(array()));
->will($this->returnValue([]));
// Get the index once.
$index1 = $manager->getIndex();