Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -353,15 +353,87 @@ display:
|
|||
destination: true
|
||||
plugin_id: entity_operations
|
||||
filters:
|
||||
status_extra:
|
||||
id: status_extra
|
||||
title:
|
||||
id: title
|
||||
table: node_field_data
|
||||
field: status_extra
|
||||
operator: '='
|
||||
value: false
|
||||
plugin_id: node_status
|
||||
field: title
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: ''
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: title_op
|
||||
label: Title
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: title_op
|
||||
identifier: title
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
entity_type: node
|
||||
entity_field: title
|
||||
type:
|
||||
id: type
|
||||
table: node_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: type_op
|
||||
label: 'Content type'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: type_op
|
||||
identifier: type
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: bundle
|
||||
entity_type: node
|
||||
entity_field: type
|
||||
status:
|
||||
id: status
|
||||
table: node_field_data
|
||||
|
@ -408,87 +480,6 @@ display:
|
|||
plugin_id: boolean
|
||||
entity_type: node
|
||||
entity_field: status
|
||||
type:
|
||||
id: type
|
||||
table: node_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: type_op
|
||||
label: 'Content type'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: type_op
|
||||
identifier: type
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: bundle
|
||||
entity_type: node
|
||||
entity_field: type
|
||||
title:
|
||||
id: title
|
||||
table: node_field_data
|
||||
field: title
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: ''
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: title_op
|
||||
label: Title
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: title_op
|
||||
identifier: title
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
entity_type: node
|
||||
entity_field: title
|
||||
langcode:
|
||||
id: langcode
|
||||
table: node_field_data
|
||||
|
@ -530,6 +521,15 @@ display:
|
|||
plugin_id: language
|
||||
entity_type: node
|
||||
entity_field: langcode
|
||||
status_extra:
|
||||
id: status_extra
|
||||
table: node_field_data
|
||||
field: status_extra
|
||||
operator: '='
|
||||
value: false
|
||||
plugin_id: node_status
|
||||
group: 1
|
||||
entity_type: node
|
||||
sorts: { }
|
||||
title: Content
|
||||
empty:
|
||||
|
|
|
@ -8,7 +8,10 @@ source:
|
|||
process:
|
||||
# If you are using this file to build a custom migration consider removing
|
||||
# the nid and vid fields to allow incremental migrations.
|
||||
nid: nid
|
||||
# In D7, nodes always have a tnid, but it's zero for untranslated nodes.
|
||||
# We normalize it to equal the nid in that case.
|
||||
# @see \Drupal\node\Plugin\migrate\source\d7\Node::prepareRow().
|
||||
nid: tnid
|
||||
vid: vid
|
||||
langcode:
|
||||
plugin: default_value
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
id: d7_node_translation
|
||||
label: Node translations
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- translation
|
||||
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
|
||||
source:
|
||||
plugin: d7_node
|
||||
translations: true
|
||||
process:
|
||||
# If you are using this file to build a custom migration consider removing
|
||||
# the nid field to allow incremental migrations.
|
||||
nid: tnid
|
||||
type: type
|
||||
langcode:
|
||||
plugin: default_value
|
||||
source: language
|
||||
default_value: "und"
|
||||
title: title
|
||||
uid: node_uid
|
||||
status: status
|
||||
created: created
|
||||
changed: changed
|
||||
promote: promote
|
||||
sticky: sticky
|
||||
revision_uid: revision_uid
|
||||
revision_log: log
|
||||
revision_timestamp: timestamp
|
||||
content_translation_source: source_langcode
|
||||
destination:
|
||||
plugin: entity:node
|
||||
translations: true
|
||||
content_translation_update_definitions:
|
||||
- node
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_user
|
||||
- d7_node_type
|
||||
- language
|
||||
optional:
|
||||
- d7_field_instance
|
||||
provider: migrate_drupal
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Updates all nodes in the passed-in array with the passed-in field values.
|
||||
|
@ -34,10 +33,10 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
|
|||
// We use batch processing to prevent timeout when updating a large number
|
||||
// of nodes.
|
||||
if (count($nodes) > 10) {
|
||||
$batch = array(
|
||||
'operations' => array(
|
||||
array('_node_mass_update_batch_process', array($nodes, $updates, $langcode, $load, $revisions))
|
||||
),
|
||||
$batch = [
|
||||
'operations' => [
|
||||
['_node_mass_update_batch_process', [$nodes, $updates, $langcode, $load, $revisions]]
|
||||
],
|
||||
'finished' => '_node_mass_update_batch_finished',
|
||||
'title' => t('Processing'),
|
||||
// We use a single multi-pass operation, so the default
|
||||
|
@ -47,16 +46,17 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
|
|||
// The operations do not live in the .module file, so we need to
|
||||
// tell the batch engine which file to load before calling them.
|
||||
'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
|
||||
);
|
||||
];
|
||||
batch_set($batch);
|
||||
}
|
||||
else {
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
if ($load && !$revisions) {
|
||||
$nodes = Node::loadMultiple($nodes);
|
||||
$nodes = $storage->loadMultiple($nodes);
|
||||
}
|
||||
foreach ($nodes as $node) {
|
||||
if ($load && $revisions) {
|
||||
$node = entity_revision_load('node', $node);
|
||||
$node = $storage->loadRevision($node);
|
||||
}
|
||||
_node_mass_update_helper($node, $updates, $langcode);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
|
|||
* @see node_mass_update()
|
||||
*/
|
||||
function _node_mass_update_helper(NodeInterface $node, array $updates, $langcode = NULL) {
|
||||
$langcodes = isset($langcode) ? array($langcode) : array_keys($node->getTranslationLanguages());
|
||||
$langcodes = isset($langcode) ? [$langcode] : array_keys($node->getTranslationLanguages());
|
||||
// For efficiency manually save the original node before applying any changes.
|
||||
$node->original = clone $node;
|
||||
foreach ($langcodes as $langcode) {
|
||||
|
@ -111,7 +111,7 @@ function _node_mass_update_helper(NodeInterface $node, array $updates, $langcode
|
|||
* @param bool $revisions
|
||||
* (optional) TRUE if $nodes contains an array of revision IDs instead of
|
||||
* node IDs. Defaults to FALSE; will be ignored if $load is FALSE.
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* An array of contextual key/values.
|
||||
*/
|
||||
function _node_mass_update_batch_process(array $nodes, array $updates, $langcode, $load, $revisions, &$context) {
|
||||
|
@ -122,13 +122,14 @@ function _node_mass_update_batch_process(array $nodes, array $updates, $langcode
|
|||
}
|
||||
|
||||
// Process nodes by groups of 5.
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
$count = min(5, count($context['sandbox']['nodes']));
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
// For each nid, load the node, reset the values, and save it.
|
||||
$node = array_shift($context['sandbox']['nodes']);
|
||||
if ($load) {
|
||||
$node = $revisions ?
|
||||
entity_revision_load('node', $node) : Node::load($node);
|
||||
$storage->loadRevision($node) : $storage->load($node);
|
||||
}
|
||||
$node = _node_mass_update_helper($node, $updates, $langcode);
|
||||
|
||||
|
@ -168,10 +169,10 @@ function _node_mass_update_batch_finished($success, $results, $operations) {
|
|||
else {
|
||||
drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
|
||||
$message = \Drupal::translation()->formatPlural(count($results), '1 item successfully processed:', '@count items successfully processed:');
|
||||
$item_list = array(
|
||||
$item_list = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $results,
|
||||
);
|
||||
];
|
||||
$message .= drupal_render($item_list);
|
||||
drupal_set_message($message);
|
||||
}
|
||||
|
|
|
@ -81,10 +81,10 @@ use Drupal\Core\Access\AccessResult;
|
|||
*/
|
||||
function hook_node_grants(\Drupal\Core\Session\AccountInterface $account, $op) {
|
||||
if ($account->hasPermission('access private content')) {
|
||||
$grants['example'] = array(1);
|
||||
$grants['example'] = [1];
|
||||
}
|
||||
if ($account->id()) {
|
||||
$grants['example_author'] = array($account->id());
|
||||
$grants['example_author'] = [$account->id()];
|
||||
}
|
||||
return $grants;
|
||||
}
|
||||
|
@ -158,33 +158,33 @@ function hook_node_access_records(\Drupal\node\NodeInterface $node) {
|
|||
// We only care about the node if it has been marked private. If not, it is
|
||||
// treated just like any other node and we completely ignore it.
|
||||
if ($node->private->value) {
|
||||
$grants = array();
|
||||
$grants = [];
|
||||
// Only published Catalan translations of private nodes should be viewable
|
||||
// to all users. If we fail to check $node->isPublished(), all users would be able
|
||||
// to view an unpublished node.
|
||||
if ($node->isPublished()) {
|
||||
$grants[] = array(
|
||||
$grants[] = [
|
||||
'realm' => 'example',
|
||||
'gid' => 1,
|
||||
'grant_view' => 1,
|
||||
'grant_update' => 0,
|
||||
'grant_delete' => 0,
|
||||
'langcode' => 'ca'
|
||||
);
|
||||
];
|
||||
}
|
||||
// For the example_author array, the GID is equivalent to a UID, which
|
||||
// means there are many groups of just 1 user.
|
||||
// Note that an author can always view his or her nodes, even if they
|
||||
// have status unpublished.
|
||||
if ($node->getOwnerId()) {
|
||||
$grants[] = array(
|
||||
$grants[] = [
|
||||
'realm' => 'example_author',
|
||||
'gid' => $node->getOwnerId(),
|
||||
'grant_view' => 1,
|
||||
'grant_update' => 1,
|
||||
'grant_delete' => 1,
|
||||
'langcode' => 'ca'
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $grants;
|
||||
|
@ -231,7 +231,7 @@ function hook_node_access_records_alter(&$grants, Drupal\node\NodeInterface $nod
|
|||
// Our module grants are set in $grants['example'].
|
||||
$temp = $grants['example'];
|
||||
// Now remove all module grants but our own.
|
||||
$grants = array('example' => $temp);
|
||||
$grants = ['example' => $temp];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ function hook_node_grants_alter(&$grants, \Drupal\Core\Session\AccountInterface
|
|||
// Now check the roles for this account against the restrictions.
|
||||
foreach ($account->getRoles() as $rid) {
|
||||
if (in_array($rid, $restricted)) {
|
||||
$grants = array();
|
||||
$grants = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -374,8 +374,8 @@ function hook_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Se
|
|||
* @ingroup entity_crud
|
||||
*/
|
||||
function hook_node_search_result(\Drupal\node\NodeInterface $node) {
|
||||
$rating = db_query('SELECT SUM(points) FROM {my_rating} WHERE nid = :nid', array('nid' => $node->id()))->fetchField();
|
||||
return array('rating' => \Drupal::translation()->formatPlural($rating, '1 point', '@count points'));
|
||||
$rating = db_query('SELECT SUM(points) FROM {my_rating} WHERE nid = :nid', ['nid' => $node->id()])->fetchField();
|
||||
return ['rating' => \Drupal::translation()->formatPlural($rating, '1 point', '@count points')];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,7 +394,7 @@ function hook_node_search_result(\Drupal\node\NodeInterface $node) {
|
|||
*/
|
||||
function hook_node_update_index(\Drupal\node\NodeInterface $node) {
|
||||
$text = '';
|
||||
$ratings = db_query('SELECT title, description FROM {my_ratings} WHERE nid = :nid', array(':nid' => $node->id()));
|
||||
$ratings = db_query('SELECT title, description FROM {my_ratings} WHERE nid = :nid', [':nid' => $node->id()]);
|
||||
foreach ($ratings as $rating) {
|
||||
$text .= '<h2>' . Html::escape($rating->title) . '</h2>' . Xss::filter($rating->description);
|
||||
}
|
||||
|
@ -447,24 +447,24 @@ function hook_node_update_index(\Drupal\node\NodeInterface $node) {
|
|||
function hook_ranking() {
|
||||
// If voting is disabled, we can avoid returning the array, no hard feelings.
|
||||
if (\Drupal::config('vote.settings')->get('node_enabled')) {
|
||||
return array(
|
||||
'vote_average' => array(
|
||||
return [
|
||||
'vote_average' => [
|
||||
'title' => t('Average vote'),
|
||||
// Note that we use i.sid, the search index's search item id, rather than
|
||||
// n.nid.
|
||||
'join' => array(
|
||||
'join' => [
|
||||
'type' => 'LEFT',
|
||||
'table' => 'vote_node_data',
|
||||
'alias' => 'vote_node_data',
|
||||
'on' => 'vote_node_data.nid = i.sid',
|
||||
),
|
||||
],
|
||||
// The highest possible score should be 1, and the lowest possible score,
|
||||
// always 0, should be 0.
|
||||
'score' => 'vote_node_data.average / CAST(%f AS DECIMAL)',
|
||||
// Pass in the highest possible voting score as a decimal argument.
|
||||
'arguments' => array(\Drupal::config('vote.settings')->get('score_max')),
|
||||
),
|
||||
);
|
||||
'arguments' => [\Drupal::config('vote.settings')->get('score_max')],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,16 +486,16 @@ function hook_ranking() {
|
|||
* @see entity_crud
|
||||
*/
|
||||
function hook_node_links_alter(array &$links, NodeInterface $entity, array &$context) {
|
||||
$links['mymodule'] = array(
|
||||
$links['mymodule'] = [
|
||||
'#theme' => 'links__node__mymodule',
|
||||
'#attributes' => array('class' => array('links', 'inline')),
|
||||
'#links' => array(
|
||||
'node-report' => array(
|
||||
'#attributes' => ['class' => ['links', 'inline']],
|
||||
'#links' => [
|
||||
'node-report' => [
|
||||
'title' => t('Report'),
|
||||
'url' => Url::fromRoute('node_test.report', ['node' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("node/{$entity->id()}/report")]]),
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Install, update and uninstall functions for the node module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
|
@ -12,26 +13,26 @@ use Drupal\user\RoleInterface;
|
|||
* Implements hook_requirements().
|
||||
*/
|
||||
function node_requirements($phase) {
|
||||
$requirements = array();
|
||||
$requirements = [];
|
||||
if ($phase === 'runtime') {
|
||||
// Only show rebuild button if there are either 0, or 2 or more, rows
|
||||
// in the {node_access} table, or if there are modules that
|
||||
// implement hook_node_grants().
|
||||
$grant_count = \Drupal::entityManager()->getAccessControlHandler('node')->countGrants();
|
||||
if ($grant_count != 1 || count(\Drupal::moduleHandler()->getImplementations('node_grants')) > 0) {
|
||||
$value = \Drupal::translation()->formatPlural($grant_count, 'One permission in use', '@count permissions in use', array('@count' => $grant_count));
|
||||
$value = \Drupal::translation()->formatPlural($grant_count, 'One permission in use', '@count permissions in use', ['@count' => $grant_count]);
|
||||
}
|
||||
else {
|
||||
$value = t('Disabled');
|
||||
}
|
||||
|
||||
$requirements['node_access'] = array(
|
||||
$requirements['node_access'] = [
|
||||
'title' => t('Node Access Permissions'),
|
||||
'value' => $value,
|
||||
'description' => t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Rebuilding will remove all privileges to content and replace them with permissions based on the current modules and settings. Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed, content will automatically use the new permissions. <a href=":rebuild">Rebuild permissions</a>', array(
|
||||
'description' => t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Rebuilding will remove all privileges to content and replace them with permissions based on the current modules and settings. Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed, content will automatically use the new permissions. <a href=":rebuild">Rebuild permissions</a>', [
|
||||
':rebuild' => \Drupal::url('node.configure_rebuild_confirm'),
|
||||
)),
|
||||
);
|
||||
]),
|
||||
];
|
||||
}
|
||||
return $requirements;
|
||||
}
|
||||
|
@ -40,77 +41,78 @@ function node_requirements($phase) {
|
|||
* Implements hook_schema().
|
||||
*/
|
||||
function node_schema() {
|
||||
$schema['node_access'] = array(
|
||||
$schema['node_access'] = [
|
||||
'description' => 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.',
|
||||
'fields' => array(
|
||||
'nid' => array(
|
||||
'fields' => [
|
||||
'nid' => [
|
||||
'description' => 'The {node}.nid this record affects.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'langcode' => array(
|
||||
],
|
||||
'langcode' => [
|
||||
'description' => 'The {language}.langcode of this node.',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 12,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'fallback' => array(
|
||||
],
|
||||
'fallback' => [
|
||||
'description' => 'Boolean indicating whether this record should be used as a fallback if a language condition is not provided.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 1,
|
||||
),
|
||||
'gid' => array(
|
||||
'size' => 'tiny',
|
||||
],
|
||||
'gid' => [
|
||||
'description' => "The grant ID a user must possess in the specified realm to gain this row's privileges on the node.",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'realm' => array(
|
||||
],
|
||||
'realm' => [
|
||||
'description' => 'The realm in which the user must possess the grant ID. Each node access node can define one or more realms.',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'grant_view' => array(
|
||||
],
|
||||
'grant_view' => [
|
||||
'description' => 'Boolean indicating whether a user with the realm/grant pair can view this node.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'grant_update' => array(
|
||||
],
|
||||
'grant_update' => [
|
||||
'description' => 'Boolean indicating whether a user with the realm/grant pair can edit this node.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'grant_delete' => array(
|
||||
],
|
||||
'grant_delete' => [
|
||||
'description' => 'Boolean indicating whether a user with the realm/grant pair can delete this node.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
),
|
||||
'primary key' => array('nid', 'gid', 'realm', 'langcode'),
|
||||
'foreign keys' => array(
|
||||
'affected_node' => array(
|
||||
],
|
||||
],
|
||||
'primary key' => ['nid', 'gid', 'realm', 'langcode'],
|
||||
'foreign keys' => [
|
||||
'affected_node' => [
|
||||
'table' => 'node',
|
||||
'columns' => array('nid' => 'nid'),
|
||||
),
|
||||
),
|
||||
);
|
||||
'columns' => ['nid' => 'nid'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
@ -127,20 +129,20 @@ function node_install() {
|
|||
// these permissions. Doing so also allows tests to continue to operate as
|
||||
// expected without first having to manually grant these default permissions.
|
||||
if (\Drupal::moduleHandler()->moduleExists('user')) {
|
||||
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access content'));
|
||||
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access content'));
|
||||
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access content']);
|
||||
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access content']);
|
||||
}
|
||||
|
||||
// Populate the node access table.
|
||||
db_insert('node_access')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'nid' => 0,
|
||||
'gid' => 0,
|
||||
'realm' => 'all',
|
||||
'grant_view' => 1,
|
||||
'grant_update' => 0,
|
||||
'grant_delete' => 0,
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
@ -164,11 +166,11 @@ function node_update_8001() {
|
|||
// \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition()
|
||||
// with the new definition.
|
||||
$storage_definition = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Revision translation affected'))
|
||||
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE);
|
||||
->setLabel(t('Revision translation affected'))
|
||||
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE);
|
||||
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('revision_translation_affected', 'node', 'node', $storage_definition);
|
||||
|
@ -214,7 +216,33 @@ function node_update_8003() {
|
|||
// changes. SqlContentEntityStorageSchema::onEntityTypeUpdate() should be
|
||||
// fixed to automatically handle this.
|
||||
// See https://www.drupal.org/node/2554245.
|
||||
foreach (array('status', 'uid') as $field_name) {
|
||||
foreach (['status', 'uid'] as $field_name) {
|
||||
$manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition($field_name, 'node'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change {node_access}.fallback from an int to a tinyint as it is a boolean.
|
||||
*/
|
||||
function node_update_8300() {
|
||||
Database::getConnection()->schema()->changeField('node_access', 'fallback', 'fallback', [
|
||||
'description' => 'Boolean indicating whether this record should be used as a fallback if a language condition is not provided.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 1,
|
||||
'size' => 'tiny',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the 'published' entity key.
|
||||
*/
|
||||
function node_update_8301() {
|
||||
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type = $definition_update_manager->getEntityType('node');
|
||||
$keys = $entity_type->getKeys();
|
||||
$keys['published'] = 'status';
|
||||
$entity_type->set('entity_keys', $keys);
|
||||
$definition_update_manager->updateEntityType($entity_type);
|
||||
}
|
||||
|
|
|
@ -18,21 +18,6 @@
|
|||
Drupal.behaviors.nodeDetailsSummaries = {
|
||||
attach: function (context) {
|
||||
var $context = $(context);
|
||||
$context.find('.node-form-revision-information').drupalSetSummary(function (context) {
|
||||
var $revisionContext = $(context);
|
||||
var revisionCheckbox = $revisionContext.find('.js-form-item-revision input');
|
||||
|
||||
// Return 'New revision' if the 'Create new revision' checkbox is
|
||||
// checked, or if the checkbox doesn't exist, but the revision log does.
|
||||
// For users without the "Administer content" permission the checkbox
|
||||
// won't appear, but the revision log will if the content type is set to
|
||||
// auto-revision.
|
||||
if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $revisionContext.find('.js-form-item-revision-log textarea').length)) {
|
||||
return Drupal.t('New revision');
|
||||
}
|
||||
|
||||
return Drupal.t('No revision');
|
||||
});
|
||||
|
||||
$context.find('.node-form-author').drupalSetSummary(function (context) {
|
||||
var $authorContext = $(context);
|
||||
|
@ -64,22 +49,6 @@
|
|||
return Drupal.t('Not promoted');
|
||||
}
|
||||
});
|
||||
|
||||
$context.find('fieldset.node-translation-options').drupalSetSummary(function (context) {
|
||||
var $translationContext = $(context);
|
||||
var translate;
|
||||
var $checkbox = $translationContext.find('.js-form-item-translation-translate input');
|
||||
|
||||
if ($checkbox.size()) {
|
||||
translate = $checkbox.is(':checked') ? Drupal.t('Needs to be updated') : Drupal.t('Does not need to be updated');
|
||||
}
|
||||
else {
|
||||
$checkbox = $translationContext.find('.js-form-item-translation-retranslate input');
|
||||
translate = $checkbox.is(':checked') ? Drupal.t('Flag other translations as outdated') : Drupal.t('Do not flag other translations as outdated');
|
||||
}
|
||||
|
||||
return translate;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -6,10 +6,8 @@ drupal.node:
|
|||
js:
|
||||
node.js: {}
|
||||
dependencies:
|
||||
- core/jquery
|
||||
- core/drupal
|
||||
- core/drupal.entity-form
|
||||
- core/drupalSettings
|
||||
- core/drupal.form
|
||||
|
||||
drupal.node.preview:
|
||||
version: VERSION
|
||||
|
|
|
@ -31,31 +31,49 @@ use Drupal\node\NodeTypeInterface;
|
|||
|
||||
/**
|
||||
* Denotes that the node is not published.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.x.
|
||||
* Use \Drupal\node\NodeInterface::NOT_PUBLISHED instead.
|
||||
*/
|
||||
const NODE_NOT_PUBLISHED = 0;
|
||||
|
||||
/**
|
||||
* Denotes that the node is published.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.x.
|
||||
* Use \Drupal\node\NodeInterface::PUBLISHED instead.
|
||||
*/
|
||||
const NODE_PUBLISHED = 1;
|
||||
|
||||
/**
|
||||
* Denotes that the node is not promoted to the front page.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.x.
|
||||
* Use \Drupal\node\NodeInterface::NOT_PROMOTED instead.
|
||||
*/
|
||||
const NODE_NOT_PROMOTED = 0;
|
||||
|
||||
/**
|
||||
* Denotes that the node is promoted to the front page.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.x.
|
||||
* Use \Drupal\node\NodeInterface::PROMOTED instead.
|
||||
*/
|
||||
const NODE_PROMOTED = 1;
|
||||
|
||||
/**
|
||||
* Denotes that the node is not sticky at the top of the page.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.x.
|
||||
* Use \Drupal\node\NodeInterface::NOT_STICKY instead.
|
||||
*/
|
||||
const NODE_NOT_STICKY = 0;
|
||||
|
||||
/**
|
||||
* Denotes that the node is sticky at the top of the page.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.x.
|
||||
* Use \Drupal\node\NodeInterface::STICKY instead.
|
||||
*/
|
||||
const NODE_STICKY = 1;
|
||||
|
||||
|
@ -72,7 +90,7 @@ function node_help($route_name, RouteMatchInterface $route_match) {
|
|||
$message = t('The content access permissions need to be rebuilt.');
|
||||
}
|
||||
else {
|
||||
$message = t('The content access permissions need to be rebuilt. <a href=":node_access_rebuild">Rebuild permissions</a>.', array(':node_access_rebuild' => \Drupal::url('node.configure_rebuild_confirm')));
|
||||
$message = t('The content access permissions need to be rebuilt. <a href=":node_access_rebuild">Rebuild permissions</a>.', [':node_access_rebuild' => \Drupal::url('node.configure_rebuild_confirm')]);
|
||||
}
|
||||
drupal_set_message($message, 'error');
|
||||
}
|
||||
|
@ -81,19 +99,19 @@ function node_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.node':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the <a href=":field">Field module</a>). For more information, see the <a href=":node">online documentation for the Node module</a>.', array(':node' => 'https://www.drupal.org/documentation/modules/node', ':field' => \Drupal::url('help.page', array('name' => 'field')))) . '</p>';
|
||||
$output .= '<p>' . t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the <a href=":field">Field module</a>). For more information, see the <a href=":node">online documentation for the Node module</a>.', [':node' => 'https://www.drupal.org/documentation/modules/node', ':field' => \Drupal::url('help.page', ['name' => 'field'])]) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Creating content') . '</dt>';
|
||||
$output .= '<dd>' . t('When new content is created, the Node module records basic information about the content, including the author, date of creation, and the <a href=":content-type">Content type</a>. It also manages the <em>publishing options</em>, which define whether or not the content is published, promoted to the front page of the site, and/or sticky at the top of content lists. Default settings can be configured for each <a href=":content-type">type of content</a> on your site.', array(':content-type' => \Drupal::url('entity.node_type.collection'))) . '</dd>';
|
||||
$output .= '<dd>' . t('When new content is created, the Node module records basic information about the content, including the author, date of creation, and the <a href=":content-type">Content type</a>. It also manages the <em>publishing options</em>, which define whether or not the content is published, promoted to the front page of the site, and/or sticky at the top of content lists. Default settings can be configured for each <a href=":content-type">type of content</a> on your site.', [':content-type' => \Drupal::url('entity.node_type.collection')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Creating custom content types') . '</dt>';
|
||||
$output .= '<dd>' . t('The Node module gives users with the <em>Administer content types</em> permission the ability to <a href=":content-new">create new content types</a> in addition to the default ones already configured. Creating custom content types gives you the flexibility to add <a href=":field">fields</a> and configure default settings that suit the differing needs of various site content.', array(':content-new' => \Drupal::url('node.type_add'), ':field' => \Drupal::url('help.page', array('name' => 'field')))) . '</dd>';
|
||||
$output .= '<dd>' . t('The Node module gives users with the <em>Administer content types</em> permission the ability to <a href=":content-new">create new content types</a> in addition to the default ones already configured. Creating custom content types gives you the flexibility to add <a href=":field">fields</a> and configure default settings that suit the differing needs of various site content.', [':content-new' => \Drupal::url('node.type_add'), ':field' => \Drupal::url('help.page', ['name' => 'field'])]) . '</dd>';
|
||||
$output .= '<dt>' . t('Administering content') . '</dt>';
|
||||
$output .= '<dd>' . t('The <a href=":content">Content</a> page lists your content, allowing you add new content, filter, edit or delete existing content, or perform bulk operations on existing content.', array(':content' => \Drupal::url('system.admin_content'))) . '</dd>';
|
||||
$output .= '<dd>' . t('The <a href=":content">Content</a> page lists your content, allowing you add new content, filter, edit or delete existing content, or perform bulk operations on existing content.', [':content' => \Drupal::url('system.admin_content')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Creating revisions') . '</dt>';
|
||||
$output .= '<dd>' . t('The Node module also enables you to create multiple versions of any content, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>';
|
||||
$output .= '<dt>' . t('User permissions') . '</dt>';
|
||||
$output .= '<dd>' . t('The Node module makes a number of permissions available for each content type, which can be set by role on the <a href=":permissions">permissions page</a>.', array(':permissions' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-node')))) . '</dd>';
|
||||
$output .= '<dd>' . t('The Node module makes a number of permissions available for each content type, which can be set by role on the <a href=":permissions">permissions page</a>.', [':permissions' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-node'])]) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
|
||||
|
@ -103,13 +121,13 @@ function node_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'entity.entity_form_display.node.default':
|
||||
case 'entity.entity_form_display.node.form_mode':
|
||||
$type = $route_match->getParameter('node_type');
|
||||
return '<p>' . t('Content items can be edited using different form modes. Here, you can define which fields are shown and hidden when %type content is edited in each form mode, and define how the field form widgets are displayed in each form mode.', array('%type' => $type->label())) . '</p>' ;
|
||||
return '<p>' . t('Content items can be edited using different form modes. Here, you can define which fields are shown and hidden when %type content is edited in each form mode, and define how the field form widgets are displayed in each form mode.', ['%type' => $type->label()]) . '</p>' ;
|
||||
|
||||
case 'entity.entity_view_display.node.default':
|
||||
case 'entity.entity_view_display.node.view_mode':
|
||||
$type = $route_match->getParameter('node_type');
|
||||
return '<p>' . t('Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. <em>Teaser</em> is a short format that is typically used in lists of multiple content items. <em>Full content</em> is typically used when the content is displayed on its own page.') . '</p>' .
|
||||
'<p>' . t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', array('%type' => $type->label())) . '</p>';
|
||||
'<p>' . t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', ['%type' => $type->label()]) . '</p>';
|
||||
|
||||
case 'entity.node.version_history':
|
||||
return '<p>' . t('Revisions allow you to track differences between multiple versions of your content, and revert to older versions.') . '</p>';
|
||||
|
@ -131,26 +149,26 @@ function node_help($route_name, RouteMatchInterface $route_match) {
|
|||
* Implements hook_theme().
|
||||
*/
|
||||
function node_theme() {
|
||||
return array(
|
||||
'node' => array(
|
||||
return [
|
||||
'node' => [
|
||||
'render element' => 'elements',
|
||||
),
|
||||
'node_add_list' => array(
|
||||
'variables' => array('content' => NULL),
|
||||
),
|
||||
'node_edit_form' => array(
|
||||
],
|
||||
'node_add_list' => [
|
||||
'variables' => ['content' => NULL],
|
||||
],
|
||||
'node_edit_form' => [
|
||||
'render element' => 'form',
|
||||
),
|
||||
'field__node__title' => array(
|
||||
],
|
||||
'field__node__title' => [
|
||||
'base hook' => 'field',
|
||||
),
|
||||
'field__node__uid' => array(
|
||||
],
|
||||
'field__node__uid' => [
|
||||
'base hook' => 'field',
|
||||
),
|
||||
'field__node__created' => array(
|
||||
],
|
||||
'field__node__created' => [
|
||||
'base hook' => 'field',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,19 +204,19 @@ function node_entity_view_display_alter(EntityViewDisplayInterface $display, $co
|
|||
* $result, or FALSE if there are no rows in $result.
|
||||
*/
|
||||
function node_title_list(StatementInterface $result, $title = NULL) {
|
||||
$items = array();
|
||||
$items = [];
|
||||
$num_rows = FALSE;
|
||||
$nids = [];
|
||||
foreach ($result as $row) {
|
||||
// Do not use $node->label() or $node->urlInfo() here, because we only have
|
||||
// database rows, not actual nodes.
|
||||
$nids[] = $row->nid;
|
||||
$options = !empty($row->comment_count) ? array('attributes' => array('title' => \Drupal::translation()->formatPlural($row->comment_count, '1 comment', '@count comments'))) : array();
|
||||
$options = !empty($row->comment_count) ? ['attributes' => ['title' => \Drupal::translation()->formatPlural($row->comment_count, '1 comment', '@count comments')]] : [];
|
||||
$items[] = \Drupal::l($row->title, new Url('entity.node.canonical', ['node' => $row->nid], $options));
|
||||
$num_rows = TRUE;
|
||||
}
|
||||
|
||||
return $num_rows ? array('#theme' => 'item_list__node', '#items' => $items, '#title' => $title, '#cache' => ['tags' => Cache::mergeTags(['node_list'], Cache::buildTags('node', $nids))]) : FALSE;
|
||||
return $num_rows ? ['#theme' => 'item_list__node', '#items' => $items, '#title' => $title, '#cache' => ['tags' => Cache::mergeTags(['node_list'], Cache::buildTags('node', $nids))]] : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,7 +232,7 @@ function node_title_list(StatementInterface $result, $title = NULL) {
|
|||
*/
|
||||
function node_mark($nid, $timestamp) {
|
||||
|
||||
$cache = &drupal_static(__FUNCTION__, array());
|
||||
$cache = &drupal_static(__FUNCTION__, []);
|
||||
|
||||
if (\Drupal::currentUser()->isAnonymous() || !\Drupal::moduleHandler()->moduleExists('history')) {
|
||||
return MARK_READ;
|
||||
|
@ -328,23 +346,23 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') {
|
|||
'field_storage' => $field_storage,
|
||||
'bundle' => $type->id(),
|
||||
'label' => $label,
|
||||
'settings' => array('display_summary' => TRUE),
|
||||
'settings' => ['display_summary' => TRUE],
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Assign widget settings for the 'default' form mode.
|
||||
entity_get_form_display('node', $type->id(), 'default')
|
||||
->setComponent('body', array(
|
||||
->setComponent('body', [
|
||||
'type' => 'text_textarea_with_summary',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Assign display settings for the 'default' and 'teaser' view modes.
|
||||
entity_get_display('node', $type->id(), 'default')
|
||||
->setComponent('body', array(
|
||||
->setComponent('body', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_default',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// The teaser view mode is created by the Standard profile and therefore
|
||||
|
@ -352,10 +370,10 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') {
|
|||
$view_modes = \Drupal::entityManager()->getViewModes('node');
|
||||
if (isset($view_modes['teaser'])) {
|
||||
entity_get_display('node', $type->id(), 'teaser')
|
||||
->setComponent('body', array(
|
||||
->setComponent('body', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_summary_or_trimmed',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
@ -367,15 +385,15 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') {
|
|||
* Implements hook_entity_extra_field_info().
|
||||
*/
|
||||
function node_entity_extra_field_info() {
|
||||
$extra = array();
|
||||
$extra = [];
|
||||
$description = t('Node module element');
|
||||
foreach (NodeType::loadMultiple() as $bundle) {
|
||||
$extra['node'][$bundle->id()]['display']['links'] = array(
|
||||
$extra['node'][$bundle->id()]['display']['links'] = [
|
||||
'label' => t('Links'),
|
||||
'description' => $description,
|
||||
'weight' => 100,
|
||||
'visible' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $extra;
|
||||
|
@ -442,7 +460,7 @@ function node_load_multiple(array $nids = NULL, $reset = FALSE) {
|
|||
*/
|
||||
function node_load($nid = NULL, $reset = FALSE) {
|
||||
if ($reset) {
|
||||
\Drupal::entityManager()->getStorage('node')->resetCache(array($nid));
|
||||
\Drupal::entityManager()->getStorage('node')->resetCache([$nid]);
|
||||
}
|
||||
return Node::load($nid);
|
||||
}
|
||||
|
@ -457,7 +475,7 @@ function node_load($nid = NULL, $reset = FALSE) {
|
|||
* A fully-populated node entity, or NULL if the node is not found.
|
||||
*/
|
||||
function node_revision_load($vid = NULL) {
|
||||
return entity_revision_load('node', $vid);
|
||||
return \Drupal::entityTypeManager()->getStorage('node')->loadRevision($vid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -499,16 +517,16 @@ function node_is_page(NodeInterface $node) {
|
|||
* @see node_add_page()
|
||||
*/
|
||||
function template_preprocess_node_add_list(&$variables) {
|
||||
$variables['types'] = array();
|
||||
$variables['types'] = [];
|
||||
if (!empty($variables['content'])) {
|
||||
foreach ($variables['content'] as $type) {
|
||||
$variables['types'][$type->id()] = array(
|
||||
$variables['types'][$type->id()] = [
|
||||
'type' => $type->id(),
|
||||
'add_link' => \Drupal::l($type->label(), new Url('node.add', array('node_type' => $type->id()))),
|
||||
'description' => array(
|
||||
'add_link' => \Drupal::l($type->label(), new Url('node.add', ['node_type' => $type->id()])),
|
||||
'description' => [
|
||||
'#markup' => $type->getDescription(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -540,7 +558,7 @@ function node_preprocess_block(&$variables) {
|
|||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function node_theme_suggestions_node(array $variables) {
|
||||
$suggestions = array();
|
||||
$suggestions = [];
|
||||
$node = $variables['elements']['#node'];
|
||||
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
||||
|
||||
|
@ -580,18 +598,18 @@ function template_preprocess_node(&$variables) {
|
|||
$variables['author_name'] = drupal_render($variables['elements']['uid']);
|
||||
unset($variables['elements']['uid']);
|
||||
|
||||
$variables['url'] = $node->url('canonical', array(
|
||||
$variables['url'] = $node->url('canonical', [
|
||||
'language' => $node->language(),
|
||||
));
|
||||
]);
|
||||
$variables['label'] = $variables['elements']['title'];
|
||||
unset($variables['elements']['title']);
|
||||
// The 'page' variable is set to TRUE in two occasions:
|
||||
// - The view mode is 'full' and we are on the 'node.view' route.
|
||||
// - The node is in preview and view mode is either 'full' or 'default'.
|
||||
$variables['page'] = ($variables['view_mode'] == 'full' && (node_is_page($node)) || (isset($node->in_preview) && in_array($node->preview_view_mode, array('full', 'default'))));
|
||||
$variables['page'] = ($variables['view_mode'] == 'full' && (node_is_page($node)) || (isset($node->in_preview) && in_array($node->preview_view_mode, ['full', 'default'])));
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
$variables += array('content' => array());
|
||||
$variables += ['content' => []];
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
|
@ -630,10 +648,10 @@ function node_cron() {
|
|||
->execute();
|
||||
if (isset($result[0])) {
|
||||
// Make an array with definite keys and store it in the state system.
|
||||
$array = array(
|
||||
$array = [
|
||||
'min_created' => $result[0][$min_alias],
|
||||
'max_created' => $result[0][$max_alias],
|
||||
);
|
||||
];
|
||||
\Drupal::state()->set('node.min_max_update_time', $array);
|
||||
}
|
||||
}
|
||||
|
@ -644,35 +662,35 @@ function node_cron() {
|
|||
*/
|
||||
function node_ranking() {
|
||||
// Create the ranking array and add the basic ranking options.
|
||||
$ranking = array(
|
||||
'relevance' => array(
|
||||
$ranking = [
|
||||
'relevance' => [
|
||||
'title' => t('Keyword relevance'),
|
||||
// Average relevance values hover around 0.15
|
||||
'score' => 'i.relevance',
|
||||
),
|
||||
'sticky' => array(
|
||||
],
|
||||
'sticky' => [
|
||||
'title' => t('Content is sticky at top of lists'),
|
||||
// The sticky flag is either 0 or 1, which is automatically normalized.
|
||||
'score' => 'n.sticky',
|
||||
),
|
||||
'promote' => array(
|
||||
],
|
||||
'promote' => [
|
||||
'title' => t('Content is promoted to the front page'),
|
||||
// The promote flag is either 0 or 1, which is automatically normalized.
|
||||
'score' => 'n.promote',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// Add relevance based on updated date, but only if it the scale values have
|
||||
// been calculated in node_cron().
|
||||
if ($node_min_max = \Drupal::state()->get('node.min_max_update_time')) {
|
||||
$ranking['recent'] = array(
|
||||
$ranking['recent'] = [
|
||||
'title' => t('Recently created'),
|
||||
// Exponential decay with half life of 14% of the age range of nodes.
|
||||
'score' => 'EXP(-5 * (1 - (n.created - :node_oldest) / :node_range))',
|
||||
'arguments' => array(
|
||||
'arguments' => [
|
||||
':node_oldest' => $node_min_max['min_created'],
|
||||
':node_range' => max($node_min_max['max_created'] - $node_min_max['min_created'], 1),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
return $ranking;
|
||||
}
|
||||
|
@ -688,17 +706,17 @@ function node_user_cancel($edit, $account, $method) {
|
|||
->condition('uid', $account->id())
|
||||
->execute();
|
||||
module_load_include('inc', 'node', 'node.admin');
|
||||
node_mass_update($nids, array('status' => 0), NULL, TRUE);
|
||||
node_mass_update($nids, ['status' => 0], NULL, TRUE);
|
||||
break;
|
||||
|
||||
case 'user_cancel_reassign':
|
||||
// Anonymize all of the nodes for this old account.
|
||||
module_load_include('inc', 'node', 'node.admin');
|
||||
$vids = \Drupal::entityManager()->getStorage('node')->userRevisionIds($account);
|
||||
node_mass_update($vids, array(
|
||||
node_mass_update($vids, [
|
||||
'uid' => 0,
|
||||
'revision_uid' => 0,
|
||||
), NULL, TRUE, TRUE);
|
||||
], NULL, TRUE, TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -711,6 +729,7 @@ function node_user_predelete($account) {
|
|||
// @todo Introduce node_mass_delete() or make node_mass_update() more flexible.
|
||||
$nids = \Drupal::entityQuery('node')
|
||||
->condition('uid', $account->id())
|
||||
->accessCheck(FALSE)
|
||||
->execute();
|
||||
entity_delete_multiple('node', $nids);
|
||||
// Delete old revisions.
|
||||
|
@ -741,15 +760,15 @@ function node_get_recent($number = 10) {
|
|||
// have some unpublished nodes to view before adding the condition.
|
||||
$access_query = \Drupal::entityQuery('node')
|
||||
->condition('uid', $account->id())
|
||||
->condition('status', NODE_NOT_PUBLISHED);
|
||||
->condition('status', NodeInterface::NOT_PUBLISHED);
|
||||
if ($account->hasPermission('view own unpublished content') && ($own_unpublished = $access_query->execute())) {
|
||||
$query->orConditionGroup()
|
||||
->condition('status', NODE_PUBLISHED)
|
||||
->condition('status', NodeInterface::PUBLISHED)
|
||||
->condition('nid', $own_unpublished, 'IN');
|
||||
}
|
||||
else {
|
||||
// If not, restrict the query to published nodes.
|
||||
$query->condition('status', NODE_PUBLISHED);
|
||||
$query->condition('status', NodeInterface::PUBLISHED);
|
||||
}
|
||||
}
|
||||
$nids = $query
|
||||
|
@ -760,7 +779,7 @@ function node_get_recent($number = 10) {
|
|||
|
||||
$nodes = Node::loadMultiple($nids);
|
||||
|
||||
return $nodes ? $nodes : array();
|
||||
return $nodes ? $nodes : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -806,12 +825,12 @@ function node_page_top(array &$page) {
|
|||
// Add 'Back to content editing' link on preview page.
|
||||
$route_match = \Drupal::routeMatch();
|
||||
if ($route_match->getRouteName() == 'entity.node.preview') {
|
||||
$page['page_top']['node_preview'] = array(
|
||||
$page['page_top']['node_preview'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('node-preview-container', 'container-inline')
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['node-preview-container', 'container-inline']
|
||||
],
|
||||
];
|
||||
|
||||
$form = \Drupal::formBuilder()->getForm('\Drupal\node\Form\NodePreviewForm', $route_match->getParameter('node_preview'));
|
||||
$page['page_top']['node_preview']['view_mode'] = $form;
|
||||
|
@ -826,12 +845,12 @@ function node_page_top(array &$page) {
|
|||
* @see node_form_system_themes_admin_form_submit()
|
||||
*/
|
||||
function node_form_system_themes_admin_form_alter(&$form, FormStateInterface $form_state, $form_id) {
|
||||
$form['admin_theme']['use_admin_theme'] = array(
|
||||
$form['admin_theme']['use_admin_theme'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use the administration theme when editing or creating content'),
|
||||
'#description' => t('Control which roles can "View the administration theme" on the <a href=":permissions">Permissions page</a>.', array(':permissions' => Url::fromRoute('user.admin_permissions')->toString())),
|
||||
'#description' => t('Control which roles can "View the administration theme" on the <a href=":permissions">Permissions page</a>.', [':permissions' => Url::fromRoute('user.admin_permissions')->toString()]),
|
||||
'#default_value' => \Drupal::configFactory()->getEditable('node.settings')->get('use_admin_theme'),
|
||||
);
|
||||
];
|
||||
$form['#submit'][] = 'node_form_system_themes_admin_form_submit';
|
||||
}
|
||||
|
||||
|
@ -951,11 +970,11 @@ function node_node_access(NodeInterface $node, $op, $account) {
|
|||
*/
|
||||
function node_access_grants($op, AccountInterface $account) {
|
||||
// Fetch node access grants from other modules.
|
||||
$grants = \Drupal::moduleHandler()->invokeAll('node_grants', array($account, $op));
|
||||
$grants = \Drupal::moduleHandler()->invokeAll('node_grants', [$account, $op]);
|
||||
// Allow modules to alter the assigned grants.
|
||||
\Drupal::moduleHandler()->alter('node_grants', $grants, $account, $op);
|
||||
|
||||
return array_merge(array('all' => array(0)), $grants);
|
||||
return array_merge(['all' => [0]], $grants);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1149,13 +1168,13 @@ function node_access_rebuild($batch_mode = FALSE) {
|
|||
// Only recalculate if the site is using a node_access module.
|
||||
if (count(\Drupal::moduleHandler()->getImplementations('node_grants'))) {
|
||||
if ($batch_mode) {
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'title' => t('Rebuilding content access permissions'),
|
||||
'operations' => array(
|
||||
array('_node_access_rebuild_batch_operation', array()),
|
||||
),
|
||||
'operations' => [
|
||||
['_node_access_rebuild_batch_operation', []],
|
||||
],
|
||||
'finished' => '_node_access_rebuild_batch_finished'
|
||||
);
|
||||
];
|
||||
batch_set($batch);
|
||||
}
|
||||
else {
|
||||
|
@ -1173,7 +1192,7 @@ function node_access_rebuild($batch_mode = FALSE) {
|
|||
$entity_query->accessCheck(FALSE);
|
||||
$nids = $entity_query->execute();
|
||||
foreach ($nids as $nid) {
|
||||
$node_storage->resetCache(array($nid));
|
||||
$node_storage->resetCache([$nid]);
|
||||
$node = Node::load($nid);
|
||||
// To preserve database integrity, only write grants if the node
|
||||
// loads successfully.
|
||||
|
|
|
@ -14,71 +14,71 @@ use Drupal\user\Entity\User;
|
|||
* Implements hook_token_info().
|
||||
*/
|
||||
function node_token_info() {
|
||||
$type = array(
|
||||
$type = [
|
||||
'name' => t('Nodes'),
|
||||
'description' => t('Tokens related to individual content items, or "nodes".'),
|
||||
'needs-data' => 'node',
|
||||
);
|
||||
];
|
||||
|
||||
// Core tokens for nodes.
|
||||
$node['nid'] = array(
|
||||
$node['nid'] = [
|
||||
'name' => t("Content ID"),
|
||||
'description' => t('The unique ID of the content item, or "node".'),
|
||||
);
|
||||
$node['vid'] = array(
|
||||
];
|
||||
$node['vid'] = [
|
||||
'name' => t("Revision ID"),
|
||||
'description' => t("The unique ID of the node's latest revision."),
|
||||
);
|
||||
$node['type'] = array(
|
||||
];
|
||||
$node['type'] = [
|
||||
'name' => t("Content type"),
|
||||
);
|
||||
$node['type-name'] = array(
|
||||
];
|
||||
$node['type-name'] = [
|
||||
'name' => t("Content type name"),
|
||||
'description' => t("The human-readable name of the node type."),
|
||||
);
|
||||
$node['title'] = array(
|
||||
];
|
||||
$node['title'] = [
|
||||
'name' => t("Title"),
|
||||
);
|
||||
$node['body'] = array(
|
||||
];
|
||||
$node['body'] = [
|
||||
'name' => t("Body"),
|
||||
'description' => t("The main body text of the node."),
|
||||
);
|
||||
$node['summary'] = array(
|
||||
];
|
||||
$node['summary'] = [
|
||||
'name' => t("Summary"),
|
||||
'description' => t("The summary of the node's main body text."),
|
||||
);
|
||||
$node['langcode'] = array(
|
||||
];
|
||||
$node['langcode'] = [
|
||||
'name' => t('Language code'),
|
||||
'description' => t('The language code of the language the node is written in.'),
|
||||
);
|
||||
$node['url'] = array(
|
||||
];
|
||||
$node['url'] = [
|
||||
'name' => t("URL"),
|
||||
'description' => t("The URL of the node."),
|
||||
);
|
||||
$node['edit-url'] = array(
|
||||
];
|
||||
$node['edit-url'] = [
|
||||
'name' => t("Edit URL"),
|
||||
'description' => t("The URL of the node's edit page."),
|
||||
);
|
||||
];
|
||||
|
||||
// Chained tokens for nodes.
|
||||
$node['created'] = array(
|
||||
$node['created'] = [
|
||||
'name' => t("Date created"),
|
||||
'type' => 'date',
|
||||
);
|
||||
$node['changed'] = array(
|
||||
];
|
||||
$node['changed'] = [
|
||||
'name' => t("Date changed"),
|
||||
'description' => t("The date the node was most recently updated."),
|
||||
'type' => 'date',
|
||||
);
|
||||
$node['author'] = array(
|
||||
];
|
||||
$node['author'] = [
|
||||
'name' => t("Author"),
|
||||
'type' => 'user',
|
||||
);
|
||||
];
|
||||
|
||||
return array(
|
||||
'types' => array('node' => $type),
|
||||
'tokens' => array('node' => $node),
|
||||
);
|
||||
return [
|
||||
'types' => ['node' => $type],
|
||||
'tokens' => ['node' => $node],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ function node_token_info() {
|
|||
function node_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
|
||||
$token_service = \Drupal::token();
|
||||
|
||||
$url_options = array('absolute' => TRUE);
|
||||
$url_options = ['absolute' => TRUE];
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
|
@ -95,7 +95,7 @@ function node_tokens($type, $tokens, array $data, array $options, BubbleableMeta
|
|||
else {
|
||||
$langcode = LanguageInterface::LANGCODE_DEFAULT;
|
||||
}
|
||||
$replacements = array();
|
||||
$replacements = [];
|
||||
|
||||
if ($type == 'node' && !empty($data['node'])) {
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
|
@ -127,7 +127,7 @@ function node_tokens($type, $tokens, array $data, array $options, BubbleableMeta
|
|||
|
||||
case 'body':
|
||||
case 'summary':
|
||||
$translation = \Drupal::entityManager()->getTranslationFromContext($node, $langcode, array('operation' => 'node_tokens'));
|
||||
$translation = \Drupal::entityManager()->getTranslationFromContext($node, $langcode, ['operation' => 'node_tokens']);
|
||||
if ($translation->hasField('body') && ($items = $translation->get('body')) && !$items->isEmpty()) {
|
||||
$item = $items[0];
|
||||
// If the summary was requested and is not empty, use it.
|
||||
|
@ -195,15 +195,15 @@ function node_tokens($type, $tokens, array $data, array $options, BubbleableMeta
|
|||
}
|
||||
|
||||
if ($author_tokens = $token_service->findWithPrefix($tokens, 'author')) {
|
||||
$replacements += $token_service->generate('user', $author_tokens, array('user' => $node->getOwner()), $options, $bubbleable_metadata);
|
||||
$replacements += $token_service->generate('user', $author_tokens, ['user' => $node->getOwner()], $options, $bubbleable_metadata);
|
||||
}
|
||||
|
||||
if ($created_tokens = $token_service->findWithPrefix($tokens, 'created')) {
|
||||
$replacements += $token_service->generate('date', $created_tokens, array('date' => $node->getCreatedTime()), $options, $bubbleable_metadata);
|
||||
$replacements += $token_service->generate('date', $created_tokens, ['date' => $node->getCreatedTime()], $options, $bubbleable_metadata);
|
||||
}
|
||||
|
||||
if ($changed_tokens = $token_service->findWithPrefix($tokens, 'changed')) {
|
||||
$replacements += $token_service->generate('date', $changed_tokens, array('date' => $node->getChangedTime()), $options, $bubbleable_metadata);
|
||||
$replacements += $token_service->generate('date', $changed_tokens, ['date' => $node->getChangedTime()], $options, $bubbleable_metadata);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,18 +14,18 @@ use Drupal\user\Entity\Role;
|
|||
*/
|
||||
function node_views_query_substitutions(ViewExecutable $view) {
|
||||
$account = \Drupal::currentUser();
|
||||
return array(
|
||||
return [
|
||||
'***ADMINISTER_NODES***' => intval($account->hasPermission('administer nodes')),
|
||||
'***VIEW_OWN_UNPUBLISHED_NODES***' => intval($account->hasPermission('view own unpublished content')),
|
||||
'***BYPASS_NODE_ACCESS***' => intval($account->hasPermission('bypass node access')),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_analyze().
|
||||
*/
|
||||
function node_views_analyze(ViewExecutable $view) {
|
||||
$ret = array();
|
||||
$ret = [];
|
||||
// Check for something other than the default display:
|
||||
if ($view->storage->get('base_table') == 'node') {
|
||||
foreach ($view->displayHandlers as $display) {
|
||||
|
@ -38,7 +38,7 @@ function node_views_analyze(ViewExecutable $view) {
|
|||
$authenticated_role = Role::load(RoleInterface::AUTHENTICATED_ID);
|
||||
$authenticated_has_access = $authenticated_role && $authenticated_role->hasPermission('access content');
|
||||
if (!$anonymous_has_access || !$authenticated_has_access) {
|
||||
$ret[] = Analyzer::formatMessage(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display->display['display_title'])), 'warning');
|
||||
$ret[] = Analyzer::formatMessage(t('Some roles lack permission to access content, but display %display has no access control.', ['%display' => $display->display['display_title']]), 'warning');
|
||||
}
|
||||
$filters = $display->getOption('filters');
|
||||
foreach ($filters as $filter) {
|
||||
|
@ -46,7 +46,7 @@ function node_views_analyze(ViewExecutable $view) {
|
|||
continue 2;
|
||||
}
|
||||
}
|
||||
$ret[] = Analyzer::formatMessage(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display->display['display_title'])), 'warning');
|
||||
$ret[] = Analyzer::formatMessage(t('Display %display has no access control but does not contain a filter for published nodes.', ['%display' => $display->display['display_title']]), 'warning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ function node_views_analyze(ViewExecutable $view) {
|
|||
foreach ($view->displayHandlers as $display) {
|
||||
if ($display->getPluginId() == 'page') {
|
||||
if ($display->getOption('path') == 'node/%') {
|
||||
$ret[] = Analyzer::formatMessage(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', array('%display' => $display->display['display_title'])), 'warning');
|
||||
$ret[] = Analyzer::formatMessage(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', ['%display' => $display->display['display_title']]), 'warning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class NodeRevisionAccessCheck implements AccessInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $access = array();
|
||||
protected $access = [];
|
||||
|
||||
/**
|
||||
* Constructs a new NodeRevisionAccessCheck.
|
||||
|
@ -90,17 +90,17 @@ class NodeRevisionAccessCheck implements AccessInterface {
|
|||
* TRUE if the operation may be performed, FALSE otherwise.
|
||||
*/
|
||||
public function checkAccess(NodeInterface $node, AccountInterface $account, $op = 'view') {
|
||||
$map = array(
|
||||
$map = [
|
||||
'view' => 'view all revisions',
|
||||
'update' => 'revert all revisions',
|
||||
'delete' => 'delete all revisions',
|
||||
);
|
||||
];
|
||||
$bundle = $node->bundle();
|
||||
$type_map = array(
|
||||
$type_map = [
|
||||
'view' => "view $bundle revisions",
|
||||
'update' => "revert $bundle revisions",
|
||||
'delete' => "delete $bundle revisions",
|
||||
);
|
||||
];
|
||||
|
||||
if (!$node || !isset($map[$op]) || !isset($type_map[$op])) {
|
||||
// If there was no node to check against, or the $op was not one of the
|
||||
|
|
|
@ -48,7 +48,7 @@ class NodeRouteContext implements ContextProviderInterface {
|
|||
}
|
||||
elseif ($this->routeMatch->getRouteName() == 'node.add') {
|
||||
$node_type = $this->routeMatch->getParameter('node_type');
|
||||
$value = Node::create(array('type' => $node_type->id()));
|
||||
$value = Node::create(['type' => $node_type->id()]);
|
||||
}
|
||||
|
||||
$cacheability = new CacheableMetadata();
|
||||
|
|
|
@ -74,7 +74,7 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
|
|||
],
|
||||
];
|
||||
|
||||
$content = array();
|
||||
$content = [];
|
||||
|
||||
// Only use node types the user has access to.
|
||||
foreach ($this->entityManager()->getStorage('node_type')->loadMultiple() as $type) {
|
||||
|
@ -88,7 +88,7 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
|
|||
// Bypass the node/add listing if only one content type is available.
|
||||
if (count($content) == 1) {
|
||||
$type = array_shift($content);
|
||||
return $this->redirect('node.add', array('node_type' => $type->id()));
|
||||
return $this->redirect('node.add', ['node_type' => $type->id()]);
|
||||
}
|
||||
|
||||
$build['#content'] = $content;
|
||||
|
@ -106,9 +106,9 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
|
|||
* A node submission form.
|
||||
*/
|
||||
public function add(NodeTypeInterface $node_type) {
|
||||
$node = $this->entityManager()->getStorage('node')->create(array(
|
||||
$node = $this->entityManager()->getStorage('node')->create([
|
||||
'type' => $node_type->id(),
|
||||
));
|
||||
]);
|
||||
|
||||
$form = $this->entityFormBuilder()->getForm($node);
|
||||
|
||||
|
@ -144,7 +144,7 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
|
|||
*/
|
||||
public function revisionPageTitle($node_revision) {
|
||||
$node = $this->entityManager()->getStorage('node')->loadRevision($node_revision);
|
||||
return $this->t('Revision of %title from %date', array('%title' => $node->label(), '%date' => format_date($node->getRevisionCreationTime())));
|
||||
return $this->t('Revision of %title from %date', ['%title' => $node->label(), '%date' => format_date($node->getRevisionCreationTime())]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,12 +166,12 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
|
|||
$type = $node->getType();
|
||||
|
||||
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $node->label()]) : $this->t('Revisions for %title', ['%title' => $node->label()]);
|
||||
$header = array($this->t('Revision'), $this->t('Operations'));
|
||||
$header = [$this->t('Revision'), $this->t('Operations')];
|
||||
|
||||
$revert_permission = (($account->hasPermission("revert $type revisions") || $account->hasPermission('revert all revisions') || $account->hasPermission('administer nodes')) && $node->access('update'));
|
||||
$delete_permission = (($account->hasPermission("delete $type revisions") || $account->hasPermission('delete all revisions') || $account->hasPermission('administer nodes')) && $node->access('delete'));
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
$default_revision = $node->getRevisionId();
|
||||
|
||||
foreach ($this->getRevisionIds($node, $node_storage) as $vid) {
|
||||
|
@ -254,17 +254,17 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
|
|||
}
|
||||
}
|
||||
|
||||
$build['node_revisions_table'] = array(
|
||||
$build['node_revisions_table'] = [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#header' => $header,
|
||||
'#attached' => array(
|
||||
'library' => array('node/drupal.node.admin'),
|
||||
),
|
||||
'#attached' => [
|
||||
'library' => ['node/drupal.node.admin'],
|
||||
],
|
||||
'#attributes' => ['class' => 'node-revision-table'],
|
||||
);
|
||||
];
|
||||
|
||||
$build['pager'] = array('#type' => 'pager');
|
||||
$build['pager'] = ['#type' => 'pager'];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
|
|||
* The page title.
|
||||
*/
|
||||
public function addPageTitle(NodeTypeInterface $node_type) {
|
||||
return $this->t('Create @name', array('@name' => $node_type->label()));
|
||||
return $this->t('Create @name', ['@name' => $node_type->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,24 +68,24 @@ class NodeViewController extends EntityViewController {
|
|||
// metadata if we have to check access.
|
||||
if ($this->currentUser->isAuthenticated() || $url->access($this->currentUser)) {
|
||||
// Set the node path as the canonical URL to prevent duplicate content.
|
||||
$build['#attached']['html_head_link'][] = array(
|
||||
array(
|
||||
$build['#attached']['html_head_link'][] = [
|
||||
[
|
||||
'rel' => $rel,
|
||||
'href' => $url->toString(),
|
||||
),
|
||||
],
|
||||
TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
if ($rel == 'canonical') {
|
||||
// Set the non-aliased canonical path as a default shortlink.
|
||||
$build['#attached']['html_head_link'][] = array(
|
||||
array(
|
||||
$build['#attached']['html_head_link'][] = [
|
||||
[
|
||||
'rel' => 'shortlink',
|
||||
'href' => $url->setOption('alias', TRUE)->toString(),
|
||||
),
|
||||
],
|
||||
TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\node\Entity;
|
|||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityPublishedTrait;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
@ -17,6 +18,7 @@ use Drupal\user\UserInterface;
|
|||
* @ContentEntityType(
|
||||
* id = "node",
|
||||
* label = @Translation("Content"),
|
||||
* label_collection = @Translation("Content"),
|
||||
* label_singular = @Translation("content item"),
|
||||
* label_plural = @Translation("content items"),
|
||||
* label_count = @PluralTranslation(
|
||||
|
@ -45,6 +47,7 @@ use Drupal\user\UserInterface;
|
|||
* data_table = "node_field_data",
|
||||
* revision_table = "node_revision",
|
||||
* revision_data_table = "node_field_revision",
|
||||
* show_revision_ui = TRUE,
|
||||
* translatable = TRUE,
|
||||
* list_cache_contexts = { "user.node_grants:view" },
|
||||
* entity_keys = {
|
||||
|
@ -55,6 +58,7 @@ use Drupal\user\UserInterface;
|
|||
* "langcode" = "langcode",
|
||||
* "uuid" = "uuid",
|
||||
* "status" = "status",
|
||||
* "published" = "status",
|
||||
* "uid" = "uid",
|
||||
* },
|
||||
* bundle_entity_type = "node_type",
|
||||
|
@ -73,6 +77,7 @@ use Drupal\user\UserInterface;
|
|||
class Node extends ContentEntityBase implements NodeInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
use EntityPublishedTrait;
|
||||
|
||||
/**
|
||||
* Whether the node is being previewed or not.
|
||||
|
@ -224,7 +229,7 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPromoted($promoted) {
|
||||
$this->set('promote', $promoted ? NODE_PROMOTED : NODE_NOT_PROMOTED);
|
||||
$this->set('promote', $promoted ? NodeInterface::PROMOTED : NodeInterface::NOT_PROMOTED);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -239,21 +244,7 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSticky($sticky) {
|
||||
$this->set('sticky', $sticky ? NODE_STICKY : NODE_NOT_STICKY);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
$this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED);
|
||||
$this->set('sticky', $sticky ? NodeInterface::STICKY : NodeInterface::NOT_STICKY);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -367,6 +358,7 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
$fields += static::publishedBaseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['title'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Title'))
|
||||
|
@ -374,15 +366,15 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('max_length', 255)
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
'weight' => -5,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -5,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
|
||||
|
@ -392,43 +384,36 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
->setSetting('target_type', 'user')
|
||||
->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId')
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'author',
|
||||
'weight' => 0,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 5,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'placeholder' => '',
|
||||
),
|
||||
))
|
||||
],
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the node is published.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Authored on'))
|
||||
->setDescription(t('The time that the node was created.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'timestamp',
|
||||
'weight' => 0,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'datetime_timestamp',
|
||||
'weight' => 10,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||
|
@ -442,13 +427,13 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setDefaultValue(TRUE)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'boolean_checkbox',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'display_label' => TRUE,
|
||||
),
|
||||
],
|
||||
'weight' => 15,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['sticky'] = BaseFieldDefinition::create('boolean')
|
||||
|
@ -456,13 +441,13 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setDefaultValue(FALSE)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'boolean_checkbox',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'display_label' => TRUE,
|
||||
),
|
||||
],
|
||||
'weight' => 16,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['revision_timestamp'] = BaseFieldDefinition::create('created')
|
||||
|
@ -483,13 +468,13 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
->setDescription(t('Briefly describe the changes you have made.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setDefaultValue('')
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textarea',
|
||||
'weight' => 25,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'rows' => 4,
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
|
||||
$fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Revision translation affected'))
|
||||
|
@ -510,7 +495,7 @@ class Node extends ContentEntityBase implements NodeInterface {
|
|||
* An array of default values.
|
||||
*/
|
||||
public static function getCurrentUserId() {
|
||||
return array(\Drupal::currentUser()->id());
|
||||
return [\Drupal::currentUser()->id()];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -182,10 +182,10 @@ class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface {
|
|||
drupal_set_message(\Drupal::translation()->formatPlural($update_count,
|
||||
'Changed the content type of 1 post from %old-type to %type.',
|
||||
'Changed the content type of @count posts from %old-type to %type.',
|
||||
array(
|
||||
[
|
||||
'%old-type' => $this->getOriginalId(),
|
||||
'%type' => $this->id(),
|
||||
)));
|
||||
]));
|
||||
}
|
||||
}
|
||||
if ($update) {
|
||||
|
@ -205,4 +205,11 @@ class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface {
|
|||
$storage->resetCache(array_keys($entities));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function shouldCreateNewRevision() {
|
||||
return $this->isNewRevision();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class DeleteMultiple extends ConfirmFormBase {
|
|||
*
|
||||
* @var string[][]
|
||||
*/
|
||||
protected $nodeInfo = array();
|
||||
protected $nodeInfo = [];
|
||||
|
||||
/**
|
||||
* The tempstore factory.
|
||||
|
@ -130,10 +130,10 @@ class DeleteMultiple extends ConfirmFormBase {
|
|||
}
|
||||
}
|
||||
|
||||
$form['nodes'] = array(
|
||||
$form['nodes'] = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
);
|
||||
];
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
return $form;
|
||||
|
@ -167,7 +167,7 @@ class DeleteMultiple extends ConfirmFormBase {
|
|||
|
||||
if ($delete_nodes) {
|
||||
$this->storage->delete($delete_nodes);
|
||||
$this->logger('content')->notice('Deleted @count posts.', array('@count' => count($delete_nodes)));
|
||||
$this->logger('content')->notice('Deleted @count posts.', ['@count' => count($delete_nodes)]);
|
||||
}
|
||||
|
||||
if ($delete_translations) {
|
||||
|
@ -182,7 +182,7 @@ class DeleteMultiple extends ConfirmFormBase {
|
|||
}
|
||||
if ($count) {
|
||||
$total_count += $count;
|
||||
$this->logger('content')->notice('Deleted @count content translations.', array('@count' => $count));
|
||||
$this->logger('content')->notice('Deleted @count content translations.', ['@count' => $count]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,10 @@ class NodeDeleteForm extends ContentEntityDeleteForm {
|
|||
]);
|
||||
}
|
||||
|
||||
return $this->t('The @type %title has been deleted.', array(
|
||||
return $this->t('The @type %title has been deleted.', [
|
||||
'@type' => $node_type,
|
||||
'%title' => $this->getEntity()->label(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,18 +72,18 @@ class NodePreviewForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $node = NULL) {
|
||||
$view_mode = $node->preview_view_mode;
|
||||
|
||||
$query_options = array('query' => array('uuid' => $node->uuid()));
|
||||
$query_options = ['query' => ['uuid' => $node->uuid()]];
|
||||
$query = $this->getRequest()->query;
|
||||
if ($query->has('destination')) {
|
||||
$query_options['query']['destination'] = $query->get('destination');
|
||||
}
|
||||
|
||||
$form['backlink'] = array(
|
||||
$form['backlink'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Back to content editing'),
|
||||
'#url' => $node->isNew() ? Url::fromRoute('node.add', ['node_type' => $node->bundle()]) : $node->urlInfo('edit-form'),
|
||||
'#options' => array('attributes' => array('class' => array('node-preview-backlink'))) + $query_options,
|
||||
);
|
||||
'#options' => ['attributes' => ['class' => ['node-preview-backlink']]] + $query_options,
|
||||
];
|
||||
|
||||
// Always show full as an option, even if the display is not enabled.
|
||||
$view_mode_options = ['full' => $this->t('Full')] + $this->entityManager->getViewModeOptionsByBundle('node', $node->bundle());
|
||||
|
@ -93,28 +93,28 @@ class NodePreviewForm extends FormBase {
|
|||
unset($view_mode_options['rss']);
|
||||
unset($view_mode_options['search_index']);
|
||||
|
||||
$form['uuid'] = array(
|
||||
$form['uuid'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $node->uuid(),
|
||||
);
|
||||
];
|
||||
|
||||
$form['view_mode'] = array(
|
||||
$form['view_mode'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('View mode'),
|
||||
'#options' => $view_mode_options,
|
||||
'#default_value' => $view_mode,
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'data-drupal-autosubmit' => TRUE,
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
$form['submit'] = array(
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Switch'),
|
||||
'#attributes' => array(
|
||||
'class' => array('js-hide'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['js-hide'],
|
||||
],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -81,14 +81,14 @@ class NodeRevisionDeleteForm extends ConfirmFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return t('Are you sure you want to delete the revision from %revision-date?', array('%revision-date' => format_date($this->revision->getRevisionCreationTime())));
|
||||
return t('Are you sure you want to delete the revision from %revision-date?', ['%revision-date' => format_date($this->revision->getRevisionCreationTime())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
return new Url('entity.node.version_history', array('node' => $this->revision->id()));
|
||||
return new Url('entity.node.version_history', ['node' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,17 +114,17 @@ class NodeRevisionDeleteForm extends ConfirmFormBase {
|
|||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->nodeStorage->deleteRevision($this->revision->getRevisionId());
|
||||
|
||||
$this->logger('content')->notice('@type: deleted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
|
||||
$this->logger('content')->notice('@type: deleted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
$node_type = $this->nodeTypeStorage->load($this->revision->bundle())->label();
|
||||
drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($this->revision->getRevisionCreationTime()), '@type' => $node_type, '%title' => $this->revision->label())));
|
||||
drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '@type' => $node_type, '%title' => $this->revision->label()]));
|
||||
$form_state->setRedirect(
|
||||
'entity.node.canonical',
|
||||
array('node' => $this->revision->id())
|
||||
['node' => $this->revision->id()]
|
||||
);
|
||||
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {node_field_revision} WHERE nid = :nid', array(':nid' => $this->revision->id()))->fetchField() > 1) {
|
||||
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {node_field_revision} WHERE nid = :nid', [':nid' => $this->revision->id()])->fetchField() > 1) {
|
||||
$form_state->setRedirect(
|
||||
'entity.node.version_history',
|
||||
array('node' => $this->revision->id())
|
||||
['node' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class NodeRevisionRevertForm extends ConfirmFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
return new Url('entity.node.version_history', array('node' => $this->revision->id()));
|
||||
return new Url('entity.node.version_history', ['node' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,7 +120,7 @@ class NodeRevisionRevertForm extends ConfirmFormBase {
|
|||
drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', ['@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)]));
|
||||
$form_state->setRedirect(
|
||||
'entity.node.version_history',
|
||||
array('node' => $this->revision->id())
|
||||
['node' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,11 +82,11 @@ class NodeRevisionRevertTranslationForm extends NodeRevisionRevertForm {
|
|||
$this->langcode = $langcode;
|
||||
$form = parent::buildForm($form, $form_state, $node_revision);
|
||||
|
||||
$form['revert_untranslated_fields'] = array(
|
||||
$form['revert_untranslated_fields'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Revert content shared among translations'),
|
||||
'#default_value' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -2,54 +2,26 @@
|
|||
|
||||
namespace Drupal\node\Form;
|
||||
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Entity\EntityDeleteForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for content type deletion.
|
||||
*/
|
||||
class NodeTypeDeleteConfirm extends EntityDeleteForm {
|
||||
|
||||
/**
|
||||
* The query factory to create entity queries.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $queryFactory;
|
||||
|
||||
/**
|
||||
* Constructs a new NodeTypeDeleteConfirm object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
|
||||
* The entity query object.
|
||||
*/
|
||||
public function __construct(QueryFactory $query_factory) {
|
||||
$this->queryFactory = $query_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$num_nodes = $this->queryFactory->get('node')
|
||||
$num_nodes = $this->entityTypeManager->getStorage('node')->getQuery()
|
||||
->condition('type', $this->entity->id())
|
||||
->count()
|
||||
->execute();
|
||||
if ($num_nodes) {
|
||||
$caption = '<p>' . $this->formatPlural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', array('%type' => $this->entity->label())) . '</p>';
|
||||
$caption = '<p>' . $this->formatPlural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', ['%type' => $this->entity->label()]) . '</p>';
|
||||
$form['#title'] = $this->getQuestion();
|
||||
$form['description'] = array('#markup' => $caption);
|
||||
$form['description'] = ['#markup' => $caption];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,17 +62,18 @@ class NodeAccessControlHandler extends EntityAccessControlHandler implements Nod
|
|||
return $return_as_object ? $result : $result->isAllowed();
|
||||
}
|
||||
if (!$account->hasPermission('access content')) {
|
||||
$result = AccessResult::forbidden()->cachePerPermissions();
|
||||
$result = AccessResult::forbidden("The 'access content' permission is required.")->cachePerPermissions();
|
||||
return $return_as_object ? $result : $result->isAllowed();
|
||||
}
|
||||
$result = parent::access($entity, $operation, $account, TRUE)->cachePerPermissions();
|
||||
|
||||
return $return_as_object ? $result : $result->isAllowed();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = array(), $return_as_object = FALSE) {
|
||||
public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = [], $return_as_object = FALSE) {
|
||||
$account = $this->prepareUser($account);
|
||||
|
||||
if ($account->hasPermission('bypass node access')) {
|
||||
|
@ -120,13 +121,13 @@ class NodeAccessControlHandler extends EntityAccessControlHandler implements Nod
|
|||
protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
|
||||
// Only users with the administer nodes permission can edit administrative
|
||||
// fields.
|
||||
$administrative_fields = array('uid', 'status', 'created', 'promote', 'sticky');
|
||||
$administrative_fields = ['uid', 'status', 'created', 'promote', 'sticky'];
|
||||
if ($operation == 'edit' && in_array($field_definition->getName(), $administrative_fields, TRUE)) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'administer nodes');
|
||||
}
|
||||
|
||||
// No user can change read only fields.
|
||||
$read_only_fields = array('revision_timestamp', 'revision_uid');
|
||||
$read_only_fields = ['revision_timestamp', 'revision_uid'];
|
||||
if ($operation == 'edit' && in_array($field_definition->getName(), $read_only_fields, TRUE)) {
|
||||
return AccessResult::forbidden();
|
||||
}
|
||||
|
@ -146,12 +147,12 @@ class NodeAccessControlHandler extends EntityAccessControlHandler implements Nod
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function acquireGrants(NodeInterface $node) {
|
||||
$grants = $this->moduleHandler->invokeAll('node_access_records', array($node));
|
||||
$grants = $this->moduleHandler->invokeAll('node_access_records', [$node]);
|
||||
// Let modules alter the grants.
|
||||
$this->moduleHandler->alter('node_access_records', $grants, $node);
|
||||
// If no grants are set and the node is published, then use the default grant.
|
||||
if (empty($grants) && $node->isPublished()) {
|
||||
$grants[] = array('realm' => 'all', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
|
||||
$grants[] = ['realm' => 'all', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0];
|
||||
}
|
||||
return $grants;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ interface NodeAccessControlHandlerInterface {
|
|||
* @param \Drupal\node\NodeInterface $node
|
||||
* The $node to acquire grants for.
|
||||
*
|
||||
* @return array $grants
|
||||
* @return array
|
||||
* The access rules for the node.
|
||||
*/
|
||||
public function acquireGrants(NodeInterface $node);
|
||||
|
@ -74,7 +74,7 @@ interface NodeAccessControlHandlerInterface {
|
|||
* A user object representing the user for whom the operation is to be
|
||||
* performed.
|
||||
*
|
||||
* @return int.
|
||||
* @return int
|
||||
* Status of the access check.
|
||||
*/
|
||||
public function checkAllGrants(AccountInterface $account);
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
namespace Drupal\node;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\user\PrivateTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -21,23 +23,19 @@ class NodeForm extends ContentEntityForm {
|
|||
protected $tempStoreFactory;
|
||||
|
||||
/**
|
||||
* Whether this node has been previewed or not.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 8.3.x. Use the form state
|
||||
* property 'has_been_previewed' instead.
|
||||
*/
|
||||
protected $hasBeenPreviewed = FALSE;
|
||||
|
||||
/**
|
||||
* Constructs a ContentEntityForm object.
|
||||
* Constructs a NodeForm object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
|
||||
* The factory for the temp store object.
|
||||
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
|
||||
* The entity type bundle service.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, PrivateTempStoreFactory $temp_store_factory) {
|
||||
parent::__construct($entity_manager);
|
||||
public function __construct(EntityManagerInterface $entity_manager, PrivateTempStoreFactory $temp_store_factory, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
|
||||
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
|
||||
$this->tempStoreFactory = $temp_store_factory;
|
||||
}
|
||||
|
||||
|
@ -47,29 +45,16 @@ class NodeForm extends ContentEntityForm {
|
|||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('user.private_tempstore')
|
||||
$container->get('user.private_tempstore'),
|
||||
$container->get('entity_type.bundle.info'),
|
||||
$container->get('datetime.time')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepareEntity() {
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$node = $this->entity;
|
||||
|
||||
if (!$node->isNew()) {
|
||||
// Remove the revision log message from the original node entity.
|
||||
$node->revision_log = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$this->hasBeenPreviewed = $form_state->get('has_been_previewed') ?: FALSE;
|
||||
|
||||
// Try to restore from temp store, this must be done before calling
|
||||
// parent::form().
|
||||
$store = $this->tempStoreFactory->get('node_preview');
|
||||
|
@ -95,80 +80,39 @@ class NodeForm extends ContentEntityForm {
|
|||
$this->entity->in_preview = NULL;
|
||||
|
||||
$form_state->set('has_been_previewed', TRUE);
|
||||
$this->hasBeenPreviewed = TRUE;
|
||||
}
|
||||
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$node = $this->entity;
|
||||
|
||||
if ($this->operation == 'edit') {
|
||||
$form['#title'] = $this->t('<em>Edit @type</em> @title', array('@type' => node_get_type_label($node), '@title' => $node->label()));
|
||||
$form['#title'] = $this->t('<em>Edit @type</em> @title', ['@type' => node_get_type_label($node), '@title' => $node->label()]);
|
||||
}
|
||||
|
||||
$current_user = $this->currentUser();
|
||||
|
||||
// Changed must be sent to the client, for later overwrite error checking.
|
||||
$form['changed'] = array(
|
||||
$form['changed'] = [
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => $node->getChangedTime(),
|
||||
);
|
||||
];
|
||||
|
||||
$form['advanced'] = array(
|
||||
'#type' => 'vertical_tabs',
|
||||
'#attributes' => array('class' => array('entity-meta')),
|
||||
'#weight' => 99,
|
||||
);
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
// Add a revision_log field if the "Create new revision" option is checked,
|
||||
// or if the current user has the ability to check that option.
|
||||
$form['revision_information'] = array(
|
||||
'#type' => 'details',
|
||||
'#group' => 'advanced',
|
||||
'#title' => t('Revision information'),
|
||||
// Open by default when "Create new revision" is checked.
|
||||
'#open' => $node->isNewRevision(),
|
||||
'#attributes' => array(
|
||||
'class' => array('node-form-revision-information'),
|
||||
),
|
||||
'#attached' => array(
|
||||
'library' => array('node/drupal.node'),
|
||||
),
|
||||
'#weight' => 20,
|
||||
'#optional' => TRUE,
|
||||
);
|
||||
|
||||
$form['revision'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Create new revision'),
|
||||
'#default_value' => $node->type->entity->isNewRevision(),
|
||||
'#access' => $current_user->hasPermission('administer nodes'),
|
||||
'#group' => 'revision_information',
|
||||
);
|
||||
|
||||
$form['revision_log'] += array(
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="revision"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
'#group' => 'revision_information',
|
||||
);
|
||||
$form['advanced']['#attributes']['class'][] = 'entity-meta';
|
||||
|
||||
// Node author information for administrators.
|
||||
$form['author'] = array(
|
||||
$form['author'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Authoring information'),
|
||||
'#group' => 'advanced',
|
||||
'#attributes' => array(
|
||||
'class' => array('node-form-author'),
|
||||
),
|
||||
'#attached' => array(
|
||||
'library' => array('node/drupal.node'),
|
||||
),
|
||||
'#attributes' => [
|
||||
'class' => ['node-form-author'],
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => ['node/drupal.node'],
|
||||
],
|
||||
'#weight' => 90,
|
||||
'#optional' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
if (isset($form['uid'])) {
|
||||
$form['uid']['#group'] = 'author';
|
||||
|
@ -179,19 +123,19 @@ class NodeForm extends ContentEntityForm {
|
|||
}
|
||||
|
||||
// Node options for administrators.
|
||||
$form['options'] = array(
|
||||
$form['options'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Promotion options'),
|
||||
'#group' => 'advanced',
|
||||
'#attributes' => array(
|
||||
'class' => array('node-form-options'),
|
||||
),
|
||||
'#attached' => array(
|
||||
'library' => array('node/drupal.node'),
|
||||
),
|
||||
'#attributes' => [
|
||||
'class' => ['node-form-options'],
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => ['node/drupal.node'],
|
||||
],
|
||||
'#weight' => 95,
|
||||
'#optional' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
if (isset($form['promote'])) {
|
||||
$form['promote']['#group'] = 'options';
|
||||
|
@ -203,7 +147,7 @@ class NodeForm extends ContentEntityForm {
|
|||
|
||||
$form['#attached']['library'][] = 'node/form';
|
||||
|
||||
$form['#entity_builders']['update_status'] = [$this, 'updateStatus'];
|
||||
$form['#entity_builders']['update_status'] = '::updateStatus';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -222,7 +166,7 @@ class NodeForm extends ContentEntityForm {
|
|||
*
|
||||
* @see \Drupal\node\NodeForm::form()
|
||||
*/
|
||||
function updateStatus($entity_type_id, NodeInterface $node, array $form, FormStateInterface $form_state) {
|
||||
public function updateStatus($entity_type_id, NodeInterface $node, array $form, FormStateInterface $form_state) {
|
||||
$element = $form_state->getTriggeringElement();
|
||||
if (isset($element['#published_status'])) {
|
||||
$node->setPublished($element['#published_status']);
|
||||
|
@ -292,13 +236,13 @@ class NodeForm extends ContentEntityForm {
|
|||
$element['submit']['#access'] = FALSE;
|
||||
}
|
||||
|
||||
$element['preview'] = array(
|
||||
$element['preview'] = [
|
||||
'#type' => 'submit',
|
||||
'#access' => $preview_mode != DRUPAL_DISABLED && ($node->access('create') || $node->access('update')),
|
||||
'#value' => t('Preview'),
|
||||
'#weight' => 20,
|
||||
'#submit' => array('::submitForm', '::preview'),
|
||||
);
|
||||
'#submit' => ['::submitForm', '::preview'],
|
||||
];
|
||||
|
||||
$element['delete']['#access'] = $node->access('delete');
|
||||
$element['delete']['#weight'] = 100;
|
||||
|
@ -306,32 +250,6 @@ class NodeForm extends ContentEntityForm {
|
|||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Updates the node object by processing the submitted values.
|
||||
*
|
||||
* This function can be called by a "Next" button of a wizard to update the
|
||||
* form state's entity with the current step's values before proceeding to the
|
||||
* next step.
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
// Build the node object from the submitted values.
|
||||
parent::submitForm($form, $form_state);
|
||||
$node = $this->entity;
|
||||
|
||||
// Save as a new revision if requested to do so.
|
||||
if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) {
|
||||
$node->setNewRevision();
|
||||
// If a new revision is created, save the current user as revision author.
|
||||
$node->setRevisionCreationTime(REQUEST_TIME);
|
||||
$node->setRevisionUserId(\Drupal::currentUser()->id());
|
||||
}
|
||||
else {
|
||||
$node->setNewRevision(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler for the 'preview' action.
|
||||
*
|
||||
|
@ -367,8 +285,8 @@ class NodeForm extends ContentEntityForm {
|
|||
$insert = $node->isNew();
|
||||
$node->save();
|
||||
$node_link = $node->link($this->t('View'));
|
||||
$context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link);
|
||||
$t_args = array('@type' => node_get_type_label($node), '%title' => $node->link($node->label()));
|
||||
$context = ['@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link];
|
||||
$t_args = ['@type' => node_get_type_label($node), '%title' => $node->link($node->label())];
|
||||
|
||||
if ($insert) {
|
||||
$this->logger('content')->notice('@type: added %title.', $context);
|
||||
|
@ -385,7 +303,7 @@ class NodeForm extends ContentEntityForm {
|
|||
if ($node->access('view')) {
|
||||
$form_state->setRedirect(
|
||||
'entity.node.canonical',
|
||||
array('node' => $node->id())
|
||||
['node' => $node->id()]
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -161,7 +161,7 @@ class NodeGrantDatabaseStorage implements NodeGrantDatabaseStorageInterface {
|
|||
if (!($table instanceof SelectInterface) && $table == $base_table) {
|
||||
// Set the subquery.
|
||||
$subquery = $this->database->select('node_access', 'na')
|
||||
->fields('na', array('nid'));
|
||||
->fields('na', ['nid']);
|
||||
|
||||
// If any grant exists for the specified user, then user has access to the
|
||||
// node for the specified operation.
|
||||
|
@ -202,13 +202,13 @@ class NodeGrantDatabaseStorage implements NodeGrantDatabaseStorageInterface {
|
|||
if ($delete) {
|
||||
$query = $this->database->delete('node_access')->condition('nid', $node->id());
|
||||
if ($realm) {
|
||||
$query->condition('realm', array($realm, 'all'), 'IN');
|
||||
$query->condition('realm', [$realm, 'all'], 'IN');
|
||||
}
|
||||
$query->execute();
|
||||
}
|
||||
// Only perform work when node_access modules are active.
|
||||
if (!empty($grants) && count($this->moduleHandler->getImplementations('node_grants'))) {
|
||||
$query = $this->database->insert('node_access')->fields(array('nid', 'langcode', 'fallback', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete'));
|
||||
$query = $this->database->insert('node_access')->fields(['nid', 'langcode', 'fallback', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete']);
|
||||
// If we have defined a granted langcode, use it. But if not, add a grant
|
||||
// for every language this node is translated to.
|
||||
foreach ($grants as $grant) {
|
||||
|
@ -216,7 +216,7 @@ class NodeGrantDatabaseStorage implements NodeGrantDatabaseStorageInterface {
|
|||
continue;
|
||||
}
|
||||
if (isset($grant['langcode'])) {
|
||||
$grant_languages = array($grant['langcode'] => $this->languageManager->getLanguage($grant['langcode']));
|
||||
$grant_languages = [$grant['langcode'] => $this->languageManager->getLanguage($grant['langcode'])];
|
||||
}
|
||||
else {
|
||||
$grant_languages = $node->getTranslationLanguages(TRUE);
|
||||
|
@ -253,14 +253,14 @@ class NodeGrantDatabaseStorage implements NodeGrantDatabaseStorageInterface {
|
|||
*/
|
||||
public function writeDefault() {
|
||||
$this->database->insert('node_access')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'nid' => 0,
|
||||
'realm' => 'all',
|
||||
'gid' => 0,
|
||||
'grant_view' => 1,
|
||||
'grant_update' => 0,
|
||||
'grant_delete' => 0,
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ interface NodeGrantDatabaseStorageInterface {
|
|||
* A user object representing the user for whom the operation is to be
|
||||
* performed.
|
||||
*
|
||||
* @return int.
|
||||
* @return int
|
||||
* Status of the access check.
|
||||
*/
|
||||
public function checkAll(AccountInterface $account);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\node;
|
||||
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
|
@ -10,7 +11,37 @@ use Drupal\Core\Entity\ContentEntityInterface;
|
|||
/**
|
||||
* Provides an interface defining a node entity.
|
||||
*/
|
||||
interface NodeInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface, RevisionLogInterface {
|
||||
interface NodeInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface, RevisionLogInterface, EntityPublishedInterface {
|
||||
|
||||
/**
|
||||
* Denotes that the node is not published.
|
||||
*/
|
||||
const NOT_PUBLISHED = 0;
|
||||
|
||||
/**
|
||||
* Denotes that the node is published.
|
||||
*/
|
||||
const PUBLISHED = 1;
|
||||
|
||||
/**
|
||||
* Denotes that the node is not promoted to the front page.
|
||||
*/
|
||||
const NOT_PROMOTED = 0;
|
||||
|
||||
/**
|
||||
* Denotes that the node is promoted to the front page.
|
||||
*/
|
||||
const PROMOTED = 1;
|
||||
|
||||
/**
|
||||
* Denotes that the node is not sticky at the top of the page.
|
||||
*/
|
||||
const NOT_STICKY = 0;
|
||||
|
||||
/**
|
||||
* Denotes that the node is sticky at the top of the page.
|
||||
*/
|
||||
const STICKY = 1;
|
||||
|
||||
/**
|
||||
* Gets the node type.
|
||||
|
@ -96,27 +127,6 @@ interface NodeInterface extends ContentEntityInterface, EntityChangedInterface,
|
|||
*/
|
||||
public function setSticky($sticky);
|
||||
|
||||
/**
|
||||
* Returns the node published status indicator.
|
||||
*
|
||||
* Unpublished nodes are only visible to their authors and to administrators.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the node is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a node..
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this node to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface
|
||||
* The called node entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
/**
|
||||
* Gets the node revision creation timestamp.
|
||||
*
|
||||
|
|
|
@ -68,27 +68,27 @@ class NodeListBuilder extends EntityListBuilder {
|
|||
*/
|
||||
public function buildHeader() {
|
||||
// Enable language column and filter if multiple languages are added.
|
||||
$header = array(
|
||||
$header = [
|
||||
'title' => $this->t('Title'),
|
||||
'type' => array(
|
||||
'type' => [
|
||||
'data' => $this->t('Content type'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
|
||||
),
|
||||
'author' => array(
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
|
||||
],
|
||||
'author' => [
|
||||
'data' => $this->t('Author'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_LOW),
|
||||
),
|
||||
'class' => [RESPONSIVE_PRIORITY_LOW],
|
||||
],
|
||||
'status' => $this->t('Status'),
|
||||
'changed' => array(
|
||||
'changed' => [
|
||||
'data' => $this->t('Updated'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_LOW),
|
||||
),
|
||||
);
|
||||
'class' => [RESPONSIVE_PRIORITY_LOW],
|
||||
],
|
||||
];
|
||||
if (\Drupal::languageManager()->isMultilingual()) {
|
||||
$header['language_name'] = array(
|
||||
$header['language_name'] = [
|
||||
'data' => $this->t('Language'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_LOW),
|
||||
);
|
||||
'class' => [RESPONSIVE_PRIORITY_LOW],
|
||||
];
|
||||
}
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
@ -98,26 +98,26 @@ class NodeListBuilder extends EntityListBuilder {
|
|||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/** @var \Drupal\node\NodeInterface $entity */
|
||||
$mark = array(
|
||||
$mark = [
|
||||
'#theme' => 'mark',
|
||||
'#mark_type' => node_mark($entity->id(), $entity->getChangedTime()),
|
||||
);
|
||||
];
|
||||
$langcode = $entity->language()->getId();
|
||||
$uri = $entity->urlInfo();
|
||||
$options = $uri->getOptions();
|
||||
$options += ($langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array());
|
||||
$options += ($langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : []);
|
||||
$uri->setOptions($options);
|
||||
$row['title']['data'] = array(
|
||||
$row['title']['data'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $entity->label(),
|
||||
'#suffix' => ' ' . drupal_render($mark),
|
||||
'#url' => $uri,
|
||||
);
|
||||
];
|
||||
$row['type'] = node_get_type_label($entity);
|
||||
$row['author']['data'] = array(
|
||||
$row['author']['data'] = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $entity->getOwner(),
|
||||
);
|
||||
];
|
||||
$row['status'] = $entity->isPublished() ? $this->t('published') : $this->t('not published');
|
||||
$row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
|
||||
$language_manager = \Drupal::languageManager();
|
||||
|
|
|
@ -22,7 +22,7 @@ class NodePermissions {
|
|||
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
|
||||
*/
|
||||
public function nodeTypePermissions() {
|
||||
$perms = array();
|
||||
$perms = [];
|
||||
// Generate node permissions for all node types.
|
||||
foreach (NodeType::loadMultiple() as $type) {
|
||||
$perms += $this->buildPermissions($type);
|
||||
|
@ -42,36 +42,36 @@ class NodePermissions {
|
|||
*/
|
||||
protected function buildPermissions(NodeType $type) {
|
||||
$type_id = $type->id();
|
||||
$type_params = array('%type_name' => $type->label());
|
||||
$type_params = ['%type_name' => $type->label()];
|
||||
|
||||
return array(
|
||||
"create $type_id content" => array(
|
||||
return [
|
||||
"create $type_id content" => [
|
||||
'title' => $this->t('%type_name: Create new content', $type_params),
|
||||
),
|
||||
"edit own $type_id content" => array(
|
||||
],
|
||||
"edit own $type_id content" => [
|
||||
'title' => $this->t('%type_name: Edit own content', $type_params),
|
||||
),
|
||||
"edit any $type_id content" => array(
|
||||
],
|
||||
"edit any $type_id content" => [
|
||||
'title' => $this->t('%type_name: Edit any content', $type_params),
|
||||
),
|
||||
"delete own $type_id content" => array(
|
||||
],
|
||||
"delete own $type_id content" => [
|
||||
'title' => $this->t('%type_name: Delete own content', $type_params),
|
||||
),
|
||||
"delete any $type_id content" => array(
|
||||
],
|
||||
"delete any $type_id content" => [
|
||||
'title' => $this->t('%type_name: Delete any content', $type_params),
|
||||
),
|
||||
"view $type_id revisions" => array(
|
||||
],
|
||||
"view $type_id revisions" => [
|
||||
'title' => $this->t('%type_name: View revisions', $type_params),
|
||||
),
|
||||
"revert $type_id revisions" => array(
|
||||
],
|
||||
"revert $type_id revisions" => [
|
||||
'title' => $this->t('%type_name: Revert revisions', $type_params),
|
||||
'description' => t('Role requires permission <em>view revisions</em> and <em>edit rights</em> for nodes in question, or <em>administer nodes</em>.'),
|
||||
),
|
||||
"delete $type_id revisions" => array(
|
||||
],
|
||||
"delete $type_id revisions" => [
|
||||
'title' => $this->t('%type_name: Delete revisions', $type_params),
|
||||
'description' => $this->t('Role requires permission to <em>view revisions</em> and <em>delete rights</em> for nodes in question, or <em>administer nodes</em>.'),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterfac
|
|||
public function revisionIds(NodeInterface $node) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {node_revision} WHERE nid=:nid ORDER BY vid',
|
||||
array(':nid' => $node->id())
|
||||
[':nid' => $node->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterfac
|
|||
public function userRevisionIds(AccountInterface $account) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {node_field_revision} WHERE uid = :uid ORDER BY vid',
|
||||
array(':uid' => $account->id())
|
||||
[':uid' => $account->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterfac
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(NodeInterface $node) {
|
||||
return $this->database->query('SELECT COUNT(*) FROM {node_field_revision} WHERE nid = :nid AND default_langcode = 1', array(':nid' => $node->id()))->fetchField();
|
||||
return $this->database->query('SELECT COUNT(*) FROM {node_field_revision} WHERE nid = :nid AND default_langcode = 1', [':nid' => $node->id()])->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterfac
|
|||
*/
|
||||
public function updateType($old_type, $new_type) {
|
||||
return $this->database->update('node')
|
||||
->fields(array('type' => $new_type))
|
||||
->fields(['type' => $new_type])
|
||||
->condition('type', $old_type)
|
||||
->execute();
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterfac
|
|||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language) {
|
||||
return $this->database->update('node_revision')
|
||||
->fields(array('langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED))
|
||||
->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
|
||||
->condition('langcode', $language->getId())
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -17,11 +17,10 @@ class NodeStorageSchema extends SqlContentEntityStorageSchema {
|
|||
protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
|
||||
$schema = parent::getEntitySchema($entity_type, $reset);
|
||||
|
||||
$schema['node_field_data']['indexes'] += array(
|
||||
'node__frontpage' => array('promote', 'status', 'sticky', 'created'),
|
||||
'node__status_type' => array('status', 'type', 'nid'),
|
||||
'node__title_type' => array('title', array('type', 4)),
|
||||
);
|
||||
$schema['node_field_data']['indexes'] += [
|
||||
'node__frontpage' => ['promote', 'status', 'sticky', 'created'],
|
||||
'node__title_type' => ['title', ['type', 4]],
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
|
|
@ -17,17 +17,7 @@ class NodeTranslationHandler extends ContentTranslationHandler {
|
|||
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
|
||||
parent::entityFormAlter($form, $form_state, $entity);
|
||||
|
||||
// Move the translation fieldset to a vertical tab.
|
||||
if (isset($form['content_translation'])) {
|
||||
$form['content_translation'] += array(
|
||||
'#group' => 'advanced',
|
||||
'#attributes' => array(
|
||||
'class' => array('node-translation-options'),
|
||||
),
|
||||
);
|
||||
|
||||
$form['content_translation']['#weight'] = 100;
|
||||
|
||||
// We do not need to show these values on node forms: they inherit the
|
||||
// basic node property values.
|
||||
$form['content_translation']['status']['#access'] = FALSE;
|
||||
|
@ -49,7 +39,7 @@ class NodeTranslationHandler extends ContentTranslationHandler {
|
|||
}
|
||||
}
|
||||
if (isset($status_translatable)) {
|
||||
foreach (array('publish', 'unpublish', 'submit') as $button) {
|
||||
foreach (['publish', 'unpublish', 'submit'] as $button) {
|
||||
if (isset($form['actions'][$button])) {
|
||||
$form['actions'][$button]['#value'] .= ' ' . ($status_translatable ? t('(this translation)') : t('(all translations)'));
|
||||
}
|
||||
|
@ -63,7 +53,7 @@ class NodeTranslationHandler extends ContentTranslationHandler {
|
|||
*/
|
||||
protected function entityFormTitle(EntityInterface $entity) {
|
||||
$type_name = node_get_type_label($entity);
|
||||
return t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $entity->label()));
|
||||
return t('<em>Edit @type</em> @title', ['@type' => $type_name, '@title' => $entity->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,134 +54,134 @@ class NodeTypeForm extends BundleEntityFormBase {
|
|||
// get the default values for workflow settings.
|
||||
// @todo Make it possible to get default values without an entity.
|
||||
// https://www.drupal.org/node/2318187
|
||||
$node = $this->entityManager->getStorage('node')->create(array('type' => $type->uuid()));
|
||||
$node = $this->entityManager->getStorage('node')->create(['type' => $type->uuid()]);
|
||||
}
|
||||
else {
|
||||
$form['#title'] = $this->t('Edit %label content type', array('%label' => $type->label()));
|
||||
$form['#title'] = $this->t('Edit %label content type', ['%label' => $type->label()]);
|
||||
$fields = $this->entityManager->getFieldDefinitions('node', $type->id());
|
||||
// Create a node to get the current values for workflow settings fields.
|
||||
$node = $this->entityManager->getStorage('node')->create(array('type' => $type->id()));
|
||||
$node = $this->entityManager->getStorage('node')->create(['type' => $type->id()]);
|
||||
}
|
||||
|
||||
$form['name'] = array(
|
||||
$form['name'] = [
|
||||
'#title' => t('Name'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $type->label(),
|
||||
'#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add content</em> page. This name must be unique.'),
|
||||
'#required' => TRUE,
|
||||
'#size' => 30,
|
||||
);
|
||||
];
|
||||
|
||||
$form['type'] = array(
|
||||
$form['type'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $type->id(),
|
||||
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
|
||||
'#disabled' => $type->isLocked(),
|
||||
'#machine_name' => array(
|
||||
'#machine_name' => [
|
||||
'exists' => ['Drupal\node\Entity\NodeType', 'load'],
|
||||
'source' => array('name'),
|
||||
),
|
||||
'#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array(
|
||||
'source' => ['name'],
|
||||
],
|
||||
'#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', [
|
||||
'%node-add' => t('Add content'),
|
||||
)),
|
||||
);
|
||||
]),
|
||||
];
|
||||
|
||||
$form['description'] = array(
|
||||
$form['description'] = [
|
||||
'#title' => t('Description'),
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => $type->getDescription(),
|
||||
'#description' => t('This text will be displayed on the <em>Add new content</em> page.'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['additional_settings'] = array(
|
||||
$form['additional_settings'] = [
|
||||
'#type' => 'vertical_tabs',
|
||||
'#attached' => array(
|
||||
'library' => array('node/drupal.content_types'),
|
||||
),
|
||||
);
|
||||
'#attached' => [
|
||||
'library' => ['node/drupal.content_types'],
|
||||
],
|
||||
];
|
||||
|
||||
$form['submission'] = array(
|
||||
$form['submission'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Submission form settings'),
|
||||
'#group' => 'additional_settings',
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['submission']['title_label'] = array(
|
||||
];
|
||||
$form['submission']['title_label'] = [
|
||||
'#title' => t('Title field label'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $fields['title']->getLabel(),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['submission']['preview_mode'] = array(
|
||||
];
|
||||
$form['submission']['preview_mode'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Preview before submitting'),
|
||||
'#default_value' => $type->getPreviewMode(),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
DRUPAL_DISABLED => t('Disabled'),
|
||||
DRUPAL_OPTIONAL => t('Optional'),
|
||||
DRUPAL_REQUIRED => t('Required'),
|
||||
),
|
||||
);
|
||||
$form['submission']['help'] = array(
|
||||
],
|
||||
];
|
||||
$form['submission']['help'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Explanation or submission guidelines'),
|
||||
'#default_value' => $type->getHelp(),
|
||||
'#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'),
|
||||
);
|
||||
$form['workflow'] = array(
|
||||
];
|
||||
$form['workflow'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Publishing options'),
|
||||
'#group' => 'additional_settings',
|
||||
);
|
||||
$workflow_options = array(
|
||||
];
|
||||
$workflow_options = [
|
||||
'status' => $node->status->value,
|
||||
'promote' => $node->promote->value,
|
||||
'sticky' => $node->sticky->value,
|
||||
'revision' => $type->isNewRevision(),
|
||||
);
|
||||
];
|
||||
// Prepare workflow options to be used for 'checkboxes' form element.
|
||||
$keys = array_keys(array_filter($workflow_options));
|
||||
$workflow_options = array_combine($keys, $keys);
|
||||
$form['workflow']['options'] = array(
|
||||
$form['workflow']['options'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Default options'),
|
||||
'#default_value' => $workflow_options,
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'status' => t('Published'),
|
||||
'promote' => t('Promoted to front page'),
|
||||
'sticky' => t('Sticky at top of lists'),
|
||||
'revision' => t('Create new revision'),
|
||||
),
|
||||
],
|
||||
'#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'),
|
||||
);
|
||||
];
|
||||
if ($this->moduleHandler->moduleExists('language')) {
|
||||
$form['language'] = array(
|
||||
$form['language'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Language settings'),
|
||||
'#group' => 'additional_settings',
|
||||
);
|
||||
];
|
||||
|
||||
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $type->id());
|
||||
$form['language']['language_configuration'] = array(
|
||||
$form['language']['language_configuration'] = [
|
||||
'#type' => 'language_configuration',
|
||||
'#entity_information' => array(
|
||||
'#entity_information' => [
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type->id(),
|
||||
),
|
||||
],
|
||||
'#default_value' => $language_configuration,
|
||||
);
|
||||
];
|
||||
}
|
||||
$form['display'] = array(
|
||||
$form['display'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Display settings'),
|
||||
'#group' => 'additional_settings',
|
||||
);
|
||||
$form['display']['display_submitted'] = array(
|
||||
];
|
||||
$form['display']['display_submitted'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display author and date information'),
|
||||
'#default_value' => $type->displaySubmitted(),
|
||||
'#description' => t('Author username and publish date will be displayed.'),
|
||||
);
|
||||
];
|
||||
|
||||
return $this->protectBundleIdElement($form);
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ class NodeTypeForm extends BundleEntityFormBase {
|
|||
$id = trim($form_state->getValue('type'));
|
||||
// '0' is invalid, since elsewhere we check it using empty().
|
||||
if ($id == '0') {
|
||||
$form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id)));
|
||||
$form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", ['%invalid' => $id]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,13 +214,13 @@ class NodeTypeForm extends BundleEntityFormBase {
|
|||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$type = $this->entity;
|
||||
$type->setNewRevision($form_state->getValue(array('options', 'revision')));
|
||||
$type->setNewRevision($form_state->getValue(['options', 'revision']));
|
||||
$type->set('type', trim($type->id()));
|
||||
$type->set('name', trim($type->label()));
|
||||
|
||||
$status = $type->save();
|
||||
|
||||
$t_args = array('%name' => $type->label());
|
||||
$t_args = ['%name' => $type->label()];
|
||||
|
||||
if ($status == SAVED_UPDATED) {
|
||||
drupal_set_message(t('The content type %name has been updated.', $t_args));
|
||||
|
@ -228,7 +228,7 @@ class NodeTypeForm extends BundleEntityFormBase {
|
|||
elseif ($status == SAVED_NEW) {
|
||||
node_add_body_field($type);
|
||||
drupal_set_message(t('The content type %name has been added.', $t_args));
|
||||
$context = array_merge($t_args, array('link' => $type->link($this->t('View'), 'collection')));
|
||||
$context = array_merge($t_args, ['link' => $type->link($this->t('View'), 'collection')]);
|
||||
$this->logger('node')->notice('Added content type %name.', $context);
|
||||
}
|
||||
|
||||
|
@ -242,8 +242,8 @@ class NodeTypeForm extends BundleEntityFormBase {
|
|||
// Update workflow options.
|
||||
// @todo Make it possible to get default values without an entity.
|
||||
// https://www.drupal.org/node/2318187
|
||||
$node = $this->entityManager->getStorage('node')->create(array('type' => $type->id()));
|
||||
foreach (array('status', 'promote', 'sticky') as $field_name) {
|
||||
$node = $this->entityManager->getStorage('node')->create(['type' => $type->id()]);
|
||||
foreach (['status', 'promote', 'sticky'] as $field_name) {
|
||||
$value = (bool) $form_state->getValue(['options', $field_name]);
|
||||
if ($node->$field_name->value != $value) {
|
||||
$fields[$field_name]->getConfig($type->id())->setDefaultValue($value)->save();
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
namespace Drupal\node;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Entity\RevisionableEntityBundleInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a node type entity.
|
||||
*/
|
||||
interface NodeTypeInterface extends ConfigEntityInterface {
|
||||
interface NodeTypeInterface extends ConfigEntityInterface, RevisionableEntityBundleInterface {
|
||||
|
||||
/**
|
||||
* Determines whether the node type is locked.
|
||||
|
@ -22,13 +23,17 @@ interface NodeTypeInterface extends ConfigEntityInterface {
|
|||
*
|
||||
* @return bool
|
||||
* TRUE if a new revision should be created by default.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.0 and will be removed before Drupal 9.0.0. Use
|
||||
* Drupal\Core\Entity\RevisionableEntityBundleInterface::shouldCreateNewRevision()
|
||||
* instead.
|
||||
*/
|
||||
public function isNewRevision();
|
||||
|
||||
/**
|
||||
* Sets whether a new revision should be created by default.
|
||||
*
|
||||
* @param bool $new_revision_
|
||||
* @param bool $new_revision
|
||||
* TRUE if a new revision should be created by default.
|
||||
*/
|
||||
public function setNewRevision($new_revision);
|
||||
|
|
|
@ -18,10 +18,10 @@ class NodeTypeListBuilder extends ConfigEntityListBuilder {
|
|||
*/
|
||||
public function buildHeader() {
|
||||
$header['title'] = t('Name');
|
||||
$header['description'] = array(
|
||||
$header['description'] = [
|
||||
'data' => t('Description'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
|
||||
);
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
|
||||
];
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,10 @@ class NodeTypeListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['title'] = array(
|
||||
$row['title'] = [
|
||||
'data' => $entity->label(),
|
||||
'class' => array('menu-label'),
|
||||
);
|
||||
'class' => ['menu-label'],
|
||||
];
|
||||
$row['description']['data'] = ['#markup' => $entity->getDescription()];
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
|
|
@ -28,25 +28,25 @@ class NodeViewBuilder extends EntityViewBuilder {
|
|||
$display = $displays[$bundle];
|
||||
|
||||
if ($display->getComponent('links')) {
|
||||
$build[$id]['links'] = array(
|
||||
$build[$id]['links'] = [
|
||||
'#lazy_builder' => [get_called_class() . '::renderLinks', [
|
||||
$entity->id(),
|
||||
$view_mode,
|
||||
$entity->language()->getId(),
|
||||
!empty($entity->in_preview),
|
||||
]],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Add Language field text element to node render array.
|
||||
if ($display->getComponent('langcode')) {
|
||||
$build[$id]['langcode'] = array(
|
||||
$build[$id]['langcode'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => t('Language'),
|
||||
'#markup' => $entity->language()->getName(),
|
||||
'#prefix' => '<div id="field-language-display">',
|
||||
'#suffix' => '</div>'
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,21 +81,21 @@ class NodeViewBuilder extends EntityViewBuilder {
|
|||
* A renderable array representing the node links.
|
||||
*/
|
||||
public static function renderLinks($node_entity_id, $view_mode, $langcode, $is_in_preview) {
|
||||
$links = array(
|
||||
$links = [
|
||||
'#theme' => 'links__node',
|
||||
'#pre_render' => array('drupal_pre_render_links'),
|
||||
'#attributes' => array('class' => array('links', 'inline')),
|
||||
);
|
||||
'#pre_render' => ['drupal_pre_render_links'],
|
||||
'#attributes' => ['class' => ['links', 'inline']],
|
||||
];
|
||||
|
||||
if (!$is_in_preview) {
|
||||
$entity = Node::load($node_entity_id)->getTranslation($langcode);
|
||||
$links['node'] = static::buildLinks($entity, $view_mode);
|
||||
|
||||
// Allow other modules to alter the node links.
|
||||
$hook_context = array(
|
||||
$hook_context = [
|
||||
'view_mode' => $view_mode,
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
];
|
||||
\Drupal::moduleHandler()->alter('node_links', $links, $entity, $hook_context);
|
||||
}
|
||||
return $links;
|
||||
|
@ -113,30 +113,30 @@ class NodeViewBuilder extends EntityViewBuilder {
|
|||
* An array that can be processed by drupal_pre_render_links().
|
||||
*/
|
||||
protected static function buildLinks(NodeInterface $entity, $view_mode) {
|
||||
$links = array();
|
||||
$links = [];
|
||||
|
||||
// Always display a read more link on teasers because we have no way
|
||||
// to know when a teaser view is different than a full view.
|
||||
if ($view_mode == 'teaser') {
|
||||
$node_title_stripped = strip_tags($entity->label());
|
||||
$links['node-readmore'] = array(
|
||||
'title' => t('Read more<span class="visually-hidden"> about @title</span>', array(
|
||||
$links['node-readmore'] = [
|
||||
'title' => t('Read more<span class="visually-hidden"> about @title</span>', [
|
||||
'@title' => $node_title_stripped,
|
||||
)),
|
||||
]),
|
||||
'url' => $entity->urlInfo(),
|
||||
'language' => $entity->language(),
|
||||
'attributes' => array(
|
||||
'attributes' => [
|
||||
'rel' => 'tag',
|
||||
'title' => $node_title_stripped,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'#theme' => 'links__node__node',
|
||||
'#links' => $links,
|
||||
'#attributes' => array('class' => array('links', 'inline')),
|
||||
);
|
||||
'#attributes' => ['class' => ['links', 'inline']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,15 +39,15 @@ class NodeViewsData extends EntityViewsData {
|
|||
// Use status = 1 instead of status <> 0 in WHERE statement.
|
||||
$data['node_field_data']['status']['filter']['use_equal'] = TRUE;
|
||||
|
||||
$data['node_field_data']['status_extra'] = array(
|
||||
$data['node_field_data']['status_extra'] = [
|
||||
'title' => $this->t('Published status or admin user'),
|
||||
'help' => $this->t('Filters out unpublished content if the current user cannot view it.'),
|
||||
'filter' => array(
|
||||
'filter' => [
|
||||
'field' => 'status',
|
||||
'id' => 'node_status',
|
||||
'label' => $this->t('Published status or admin user'),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['promote']['help'] = $this->t('A boolean indicating whether the node is visible on the front page.');
|
||||
$data['node_field_data']['promote']['filter']['label'] = $this->t('Promoted to front page status');
|
||||
|
@ -58,133 +58,133 @@ class NodeViewsData extends EntityViewsData {
|
|||
$data['node_field_data']['sticky']['filter']['type'] = 'yes-no';
|
||||
$data['node_field_data']['sticky']['sort']['help'] = $this->t('Whether or not the content is sticky. To list sticky content first, set this to descending.');
|
||||
|
||||
$data['node']['path'] = array(
|
||||
'field' => array(
|
||||
$data['node']['path'] = [
|
||||
'field' => [
|
||||
'title' => $this->t('Path'),
|
||||
'help' => $this->t('The aliased path to this content.'),
|
||||
'id' => 'node_path',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node']['node_bulk_form'] = array(
|
||||
$data['node']['node_bulk_form'] = [
|
||||
'title' => $this->t('Node operations bulk form'),
|
||||
'help' => $this->t('Add a form element that lets you run operations on multiple nodes.'),
|
||||
'field' => array(
|
||||
'field' => [
|
||||
'id' => 'node_bulk_form',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Bogus fields for aliasing purposes.
|
||||
|
||||
// @todo Add similar support to any date field
|
||||
// @see https://www.drupal.org/node/2337507
|
||||
$data['node_field_data']['created_fulldate'] = array(
|
||||
$data['node_field_data']['created_fulldate'] = [
|
||||
'title' => $this->t('Created date'),
|
||||
'help' => $this->t('Date in the form of CCYYMMDD.'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'created',
|
||||
'id' => 'date_fulldate',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['created_year_month'] = array(
|
||||
$data['node_field_data']['created_year_month'] = [
|
||||
'title' => $this->t('Created year + month'),
|
||||
'help' => $this->t('Date in the form of YYYYMM.'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'created',
|
||||
'id' => 'date_year_month',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['created_year'] = array(
|
||||
$data['node_field_data']['created_year'] = [
|
||||
'title' => $this->t('Created year'),
|
||||
'help' => $this->t('Date in the form of YYYY.'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'created',
|
||||
'id' => 'date_year',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['created_month'] = array(
|
||||
$data['node_field_data']['created_month'] = [
|
||||
'title' => $this->t('Created month'),
|
||||
'help' => $this->t('Date in the form of MM (01 - 12).'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'created',
|
||||
'id' => 'date_month',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['created_day'] = array(
|
||||
$data['node_field_data']['created_day'] = [
|
||||
'title' => $this->t('Created day'),
|
||||
'help' => $this->t('Date in the form of DD (01 - 31).'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'created',
|
||||
'id' => 'date_day',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['created_week'] = array(
|
||||
$data['node_field_data']['created_week'] = [
|
||||
'title' => $this->t('Created week'),
|
||||
'help' => $this->t('Date in the form of WW (01 - 53).'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'created',
|
||||
'id' => 'date_week',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['changed_fulldate'] = array(
|
||||
$data['node_field_data']['changed_fulldate'] = [
|
||||
'title' => $this->t('Updated date'),
|
||||
'help' => $this->t('Date in the form of CCYYMMDD.'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'changed',
|
||||
'id' => 'date_fulldate',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['changed_year_month'] = array(
|
||||
$data['node_field_data']['changed_year_month'] = [
|
||||
'title' => $this->t('Updated year + month'),
|
||||
'help' => $this->t('Date in the form of YYYYMM.'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'changed',
|
||||
'id' => 'date_year_month',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['changed_year'] = array(
|
||||
$data['node_field_data']['changed_year'] = [
|
||||
'title' => $this->t('Updated year'),
|
||||
'help' => $this->t('Date in the form of YYYY.'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'changed',
|
||||
'id' => 'date_year',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['changed_month'] = array(
|
||||
$data['node_field_data']['changed_month'] = [
|
||||
'title' => $this->t('Updated month'),
|
||||
'help' => $this->t('Date in the form of MM (01 - 12).'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'changed',
|
||||
'id' => 'date_month',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['changed_day'] = array(
|
||||
$data['node_field_data']['changed_day'] = [
|
||||
'title' => $this->t('Updated day'),
|
||||
'help' => $this->t('Date in the form of DD (01 - 31).'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'changed',
|
||||
'id' => 'date_day',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['changed_week'] = array(
|
||||
$data['node_field_data']['changed_week'] = [
|
||||
'title' => $this->t('Updated week'),
|
||||
'help' => $this->t('Date in the form of WW (01 - 53).'),
|
||||
'argument' => array(
|
||||
'argument' => [
|
||||
'field' => 'changed',
|
||||
'id' => 'date_week',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['uid']['help'] = $this->t('The user authoring the content. If you need more fields than the uid add the content: author relationship');
|
||||
$data['node_field_data']['uid']['filter']['id'] = 'user_name';
|
||||
|
@ -192,13 +192,13 @@ class NodeViewsData extends EntityViewsData {
|
|||
$data['node_field_data']['uid']['relationship']['help'] = $this->t('Relate content to the user who created it.');
|
||||
$data['node_field_data']['uid']['relationship']['label'] = $this->t('author');
|
||||
|
||||
$data['node']['node_listing_empty'] = array(
|
||||
$data['node']['node_listing_empty'] = [
|
||||
'title' => $this->t('Empty Node Frontpage behavior'),
|
||||
'help' => $this->t('Provides a link to the node add overview page.'),
|
||||
'area' => array(
|
||||
'area' => [
|
||||
'id' => 'node_listing_empty',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_data']['uid_revision']['title'] = $this->t('User has a revision');
|
||||
$data['node_field_data']['uid_revision']['help'] = $this->t('All nodes where a certain user has a revision');
|
||||
|
@ -225,19 +225,19 @@ class NodeViewsData extends EntityViewsData {
|
|||
$data['node_field_revision']['nid']['relationship']['title'] = $this->t('Content');
|
||||
$data['node_field_revision']['nid']['relationship']['label'] = $this->t('Get the actual content from a content revision.');
|
||||
|
||||
$data['node_field_revision']['vid'] = array(
|
||||
'argument' => array(
|
||||
$data['node_field_revision']['vid'] = [
|
||||
'argument' => [
|
||||
'id' => 'node_vid',
|
||||
'numeric' => TRUE,
|
||||
),
|
||||
'relationship' => array(
|
||||
],
|
||||
'relationship' => [
|
||||
'id' => 'standard',
|
||||
'base' => 'node_field_data',
|
||||
'base field' => 'vid',
|
||||
'title' => $this->t('Content'),
|
||||
'label' => $this->t('Get the actual content from a content revision.'),
|
||||
),
|
||||
) + $data['node_field_revision']['vid'];
|
||||
],
|
||||
] + $data['node_field_revision']['vid'];
|
||||
|
||||
$data['node_field_revision']['langcode']['help'] = $this->t('The language the original content is in.');
|
||||
|
||||
|
@ -259,52 +259,52 @@ class NodeViewsData extends EntityViewsData {
|
|||
|
||||
$data['node_field_revision']['langcode']['help'] = $this->t('The language of the content or translation.');
|
||||
|
||||
$data['node_field_revision']['link_to_revision'] = array(
|
||||
'field' => array(
|
||||
$data['node_field_revision']['link_to_revision'] = [
|
||||
'field' => [
|
||||
'title' => $this->t('Link to revision'),
|
||||
'help' => $this->t('Provide a simple link to the revision.'),
|
||||
'id' => 'node_revision_link',
|
||||
'click sortable' => FALSE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_revision']['revert_revision'] = array(
|
||||
'field' => array(
|
||||
$data['node_field_revision']['revert_revision'] = [
|
||||
'field' => [
|
||||
'title' => $this->t('Link to revert revision'),
|
||||
'help' => $this->t('Provide a simple link to revert to the revision.'),
|
||||
'id' => 'node_revision_link_revert',
|
||||
'click sortable' => FALSE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_field_revision']['delete_revision'] = array(
|
||||
'field' => array(
|
||||
$data['node_field_revision']['delete_revision'] = [
|
||||
'field' => [
|
||||
'title' => $this->t('Link to delete revision'),
|
||||
'help' => $this->t('Provide a simple link to delete the content revision.'),
|
||||
'id' => 'node_revision_link_delete',
|
||||
'click sortable' => FALSE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Define the base group of this table. Fields that don't have a group defined
|
||||
// will go into this field by default.
|
||||
$data['node_access']['table']['group'] = $this->t('Content access');
|
||||
|
||||
// For other base tables, explain how we join.
|
||||
$data['node_access']['table']['join'] = array(
|
||||
'node_field_data' => array(
|
||||
$data['node_access']['table']['join'] = [
|
||||
'node_field_data' => [
|
||||
'left_field' => 'nid',
|
||||
'field' => 'nid',
|
||||
),
|
||||
);
|
||||
$data['node_access']['nid'] = array(
|
||||
],
|
||||
];
|
||||
$data['node_access']['nid'] = [
|
||||
'title' => $this->t('Access'),
|
||||
'help' => $this->t('Filter by access.'),
|
||||
'filter' => array(
|
||||
'filter' => [
|
||||
'id' => 'node_access',
|
||||
'help' => $this->t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Add search table, fields, filters, etc., but only if a page using the
|
||||
// node_search plugin is enabled.
|
||||
|
@ -324,61 +324,61 @@ class NodeViewsData extends EntityViewsData {
|
|||
// Automatically join to the node table (or actually, node_field_data).
|
||||
// Use a Views table alias to allow other modules to use this table too,
|
||||
// if they use the search index.
|
||||
$data['node_search_index']['table']['join'] = array(
|
||||
'node_field_data' => array(
|
||||
$data['node_search_index']['table']['join'] = [
|
||||
'node_field_data' => [
|
||||
'left_field' => 'nid',
|
||||
'field' => 'sid',
|
||||
'table' => 'search_index',
|
||||
'extra' => "node_search_index.type = 'node_search' AND node_search_index.langcode = node_field_data.langcode",
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
$data['node_search_total']['table']['join'] = array(
|
||||
'node_search_index' => array(
|
||||
$data['node_search_total']['table']['join'] = [
|
||||
'node_search_index' => [
|
||||
'left_field' => 'word',
|
||||
'field' => 'word',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_search_dataset']['table']['join'] = array(
|
||||
'node_field_data' => array(
|
||||
$data['node_search_dataset']['table']['join'] = [
|
||||
'node_field_data' => [
|
||||
'left_field' => 'sid',
|
||||
'left_table' => 'node_search_index',
|
||||
'field' => 'sid',
|
||||
'table' => 'search_dataset',
|
||||
'extra' => 'node_search_index.type = node_search_dataset.type AND node_search_index.langcode = node_search_dataset.langcode',
|
||||
'type' => 'INNER',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_search_index']['score'] = array(
|
||||
$data['node_search_index']['score'] = [
|
||||
'title' => $this->t('Score'),
|
||||
'help' => $this->t('The score of the search item. This will not be used if the search filter is not also present.'),
|
||||
'field' => array(
|
||||
'field' => [
|
||||
'id' => 'search_score',
|
||||
'float' => TRUE,
|
||||
'no group by' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
],
|
||||
'sort' => [
|
||||
'id' => 'search_score',
|
||||
'no group by' => TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['node_search_index']['keys'] = array(
|
||||
$data['node_search_index']['keys'] = [
|
||||
'title' => $this->t('Search Keywords'),
|
||||
'help' => $this->t('The keywords to search for.'),
|
||||
'filter' => array(
|
||||
'filter' => [
|
||||
'id' => 'search_keywords',
|
||||
'no group by' => TRUE,
|
||||
'search_type' => 'node_search',
|
||||
),
|
||||
'argument' => array(
|
||||
],
|
||||
'argument' => [
|
||||
'id' => 'search',
|
||||
'no group by' => TRUE,
|
||||
'search_type' => 'node_search',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,9 +67,9 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'owner_uid' => '',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,34 +81,34 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory
|
|||
|
||||
// Use dropdown for fewer than 200 users; textbox for more than that.
|
||||
if (intval($count) < 200) {
|
||||
$options = array();
|
||||
$options = [];
|
||||
$result = $this->connection->query("SELECT uid, name FROM {users_field_data} WHERE uid > 0 AND default_langcode = 1 ORDER BY name");
|
||||
foreach ($result as $data) {
|
||||
$options[$data->uid] = $data->name;
|
||||
}
|
||||
$form['owner_uid'] = array(
|
||||
$form['owner_uid'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Username'),
|
||||
'#default_value' => $this->configuration['owner_uid'],
|
||||
'#options' => $options,
|
||||
'#description' => $description,
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['owner_uid'] = array(
|
||||
$form['owner_uid'] = [
|
||||
'#type' => 'entity_autocomplete',
|
||||
'#title' => t('Username'),
|
||||
'#target_type' => 'user',
|
||||
'#selection_setttings' => array(
|
||||
'#selection_setttings' => [
|
||||
'include_anonymous' => FALSE,
|
||||
),
|
||||
],
|
||||
'#default_value' => User::load($this->configuration['owner_uid']),
|
||||
// Validation is done in static::validateConfigurationForm().
|
||||
'#validate_reference' => FALSE,
|
||||
'#size' => '6',
|
||||
'#maxlength' => '60',
|
||||
'#description' => $description,
|
||||
);
|
||||
];
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$exists = (bool) $this->connection->queryRange('SELECT 1 FROM {users_field_data} WHERE uid = :uid AND default_langcode = 1', 0, 1, array(':uid' => $form_state->getValue('owner_uid')))->fetchField();
|
||||
$exists = (bool) $this->connection->queryRange('SELECT 1 FROM {users_field_data} WHERE uid = :uid AND default_langcode = 1', 0, 1, [':uid' => $form_state->getValue('owner_uid')])->fetchField();
|
||||
if (!$exists) {
|
||||
$form_state->setErrorByName('owner_uid', t('Enter a valid username.'));
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ class DeleteNode extends ActionBase implements ContainerFactoryPluginInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($object = NULL) {
|
||||
$this->executeMultiple(array($object));
|
||||
$this->executeMultiple([$object]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,8 +20,7 @@ class PublishNode extends ActionBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($entity = NULL) {
|
||||
$entity->status = NODE_PUBLISHED;
|
||||
$entity->save();
|
||||
$entity->setPublished()->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,8 +20,7 @@ class StickyNode extends ActionBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($entity = NULL) {
|
||||
$entity->sticky = NODE_STICKY;
|
||||
$entity->save();
|
||||
$entity->setSticky(TRUE)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,21 +36,21 @@ class UnpublishByKeywordNode extends ConfigurableActionBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
'keywords' => array(),
|
||||
);
|
||||
return [
|
||||
'keywords' => [],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['keywords'] = array(
|
||||
$form['keywords'] = [
|
||||
'#title' => t('Keywords'),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t('The content will be unpublished if it contains any of the phrases above. Use a case-sensitive, comma-separated list of phrases. Example: funny, bungee jumping, "Company, Inc."'),
|
||||
'#default_value' => Tags::implode($this->configuration['keywords']),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ class UnpublishNode extends ActionBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($entity = NULL) {
|
||||
$entity->status = NODE_NOT_PUBLISHED;
|
||||
$entity->save();
|
||||
$entity->setUnpublished()->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,8 +20,7 @@ class UnstickyNode extends ActionBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($entity = NULL) {
|
||||
$entity->sticky = NODE_NOT_STICKY;
|
||||
$entity->save();
|
||||
$entity->setSticky(FALSE)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,9 +21,9 @@ class SyndicateBlock extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'block_count' => 10,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,10 +37,10 @@ class SyndicateBlock extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return array(
|
||||
return [
|
||||
'#theme' => 'feed_icon',
|
||||
'#url' => 'rss.xml',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,17 +64,17 @@ class NodeType extends ConditionPluginBase implements ContainerFactoryPluginInte
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$options = array();
|
||||
$options = [];
|
||||
$node_types = $this->entityStorage->loadMultiple();
|
||||
foreach ($node_types as $type) {
|
||||
$options[$type->id()] = $type->label();
|
||||
}
|
||||
$form['bundles'] = array(
|
||||
$form['bundles'] = [
|
||||
'#title' => $this->t('Node types'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->configuration['bundles'],
|
||||
);
|
||||
];
|
||||
return parent::buildConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
@ -94,10 +94,10 @@ class NodeType extends ConditionPluginBase implements ContainerFactoryPluginInte
|
|||
$bundles = $this->configuration['bundles'];
|
||||
$last = array_pop($bundles);
|
||||
$bundles = implode(', ', $bundles);
|
||||
return $this->t('The node bundle is @bundles or @last', array('@bundles' => $bundles, '@last' => $last));
|
||||
return $this->t('The node bundle is @bundles or @last', ['@bundles' => $bundles, '@last' => $last]);
|
||||
}
|
||||
$bundle = reset($this->configuration['bundles']);
|
||||
return $this->t('The node bundle is @bundle', array('@bundle' => $bundle));
|
||||
return $this->t('The node bundle is @bundle', ['@bundle' => $bundle]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,7 +115,7 @@ class NodeType extends ConditionPluginBase implements ContainerFactoryPluginInte
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array('bundles' => array()) + parent::defaultConfiguration();
|
||||
return ['bundles' => []] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\node\Plugin\EntityReferenceSelection;
|
|||
|
||||
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Provides specific access control for the node entity type.
|
||||
|
@ -38,7 +39,7 @@ class NodeSelection extends DefaultSelection {
|
|||
// modules in use on the site. As long as one access control module is there,
|
||||
// it is supposed to handle this check.
|
||||
if (!$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants'))) {
|
||||
$query->condition('status', NODE_PUBLISHED);
|
||||
$query->condition('status', NodeInterface::PUBLISHED);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
|
|
@ -102,12 +102,12 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $advanced = array(
|
||||
'type' => array('column' => 'n.type'),
|
||||
'language' => array('column' => 'i.langcode'),
|
||||
'author' => array('column' => 'n.uid'),
|
||||
'term' => array('column' => 'ti.tid', 'join' => array('table' => 'taxonomy_index', 'alias' => 'ti', 'condition' => 'n.nid = ti.nid')),
|
||||
);
|
||||
protected $advanced = [
|
||||
'type' => ['column' => 'n.type'],
|
||||
'language' => ['column' => 'i.langcode'],
|
||||
'author' => ['column' => 'n.uid'],
|
||||
'term' => ['column' => 'ti.tid', 'join' => ['table' => 'taxonomy_index', 'alias' => 'ti', 'condition' => 'n.nid = ti.nid']],
|
||||
];
|
||||
|
||||
/**
|
||||
* A constant for setting and checking the query string.
|
||||
|
@ -207,7 +207,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,7 +225,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
|
||||
// Build matching conditions.
|
||||
$query = $this->database
|
||||
->select('search_index', 'i', array('target' => 'replica'))
|
||||
->select('search_index', 'i', ['target' => 'replica'])
|
||||
->extend('Drupal\search\SearchQuery')
|
||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender');
|
||||
$query->join('node_field_data', 'n', 'n.nid = i.sid AND n.langcode = i.langcode');
|
||||
|
@ -242,7 +242,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
// the keywords string, and some of which are separate conditions.
|
||||
$parameters = $this->getParameters();
|
||||
if (!empty($parameters['f']) && is_array($parameters['f'])) {
|
||||
$filters = array();
|
||||
$filters = [];
|
||||
// Match any query value that is an expected option and a value
|
||||
// separated by ':' like 'term:27'.
|
||||
$pattern = '/^(' . implode('|', array_keys($this->advanced)) . '):([^ ]*)/i';
|
||||
|
@ -277,7 +277,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
$find = $query
|
||||
// Add the language code of the indexed item to the result of the query,
|
||||
// since the node will be rendered using the respective language.
|
||||
->fields('i', array('langcode'))
|
||||
->fields('i', ['langcode'])
|
||||
// And since SearchQuery makes these into GROUP BY queries, if we add
|
||||
// a field, for PostgreSQL we also need to make it an aggregate or a
|
||||
// GROUP BY. In this case, we want GROUP BY.
|
||||
|
@ -289,7 +289,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
$status = $query->getStatus();
|
||||
|
||||
if ($status & SearchQuery::EXPRESSIONS_IGNORED) {
|
||||
drupal_set_message($this->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => $this->searchSettings->get('and_or_limit'))), 'warning');
|
||||
drupal_set_message($this->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', ['@count' => $this->searchSettings->get('and_or_limit')]), 'warning');
|
||||
}
|
||||
|
||||
if ($status & SearchQuery::LOWER_CASE_OR) {
|
||||
|
@ -313,7 +313,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
* Array of search result item render arrays (empty array if no results).
|
||||
*/
|
||||
protected function prepareResults(StatementInterface $found) {
|
||||
$results = array();
|
||||
$results = [];
|
||||
|
||||
$node_storage = $this->entityManager->getStorage('node');
|
||||
$node_render = $this->entityManager->getViewBuilder('node');
|
||||
|
@ -329,7 +329,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
$type = $this->entityManager->getStorage('node_type')->load($node->bundle());
|
||||
|
||||
unset($build['#theme']);
|
||||
$build['#pre_render'][] = array($this, 'removeSubmittedInfo');
|
||||
$build['#pre_render'][] = [$this, 'removeSubmittedInfo'];
|
||||
|
||||
// Fetch comments for snippet.
|
||||
$rendered = $this->renderer->renderPlain($build);
|
||||
|
@ -339,13 +339,13 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
$extra = $this->moduleHandler->invokeAll('node_search_result', [$node]);
|
||||
|
||||
$language = $this->languageManager->getLanguage($item->langcode);
|
||||
$username = array(
|
||||
$username = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $node->getOwner(),
|
||||
);
|
||||
];
|
||||
|
||||
$result = array(
|
||||
'link' => $node->url('canonical', array('absolute' => TRUE, 'language' => $language)),
|
||||
$result = [
|
||||
'link' => $node->url('canonical', ['absolute' => TRUE, 'language' => $language]),
|
||||
'type' => $type->label(),
|
||||
'title' => $node->label(),
|
||||
'node' => $node,
|
||||
|
@ -353,7 +353,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
'score' => $item->calculated_score,
|
||||
'snippet' => search_excerpt($keys, $rendered, $item->langcode),
|
||||
'langcode' => $node->language()->getId(),
|
||||
);
|
||||
];
|
||||
|
||||
$this->addCacheableDependency($node);
|
||||
|
||||
|
@ -364,10 +364,10 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
$this->addCacheableDependency($node->getOwner());
|
||||
|
||||
if ($type->displaySubmitted()) {
|
||||
$result += array(
|
||||
$result += [
|
||||
'user' => $this->renderer->renderPlain($username),
|
||||
'date' => $node->getChangedTime(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$results[] = $result;
|
||||
|
@ -411,7 +411,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
if (isset($values['join']) && !isset($tables[$values['join']['alias']])) {
|
||||
$query->addJoin($values['join']['type'], $values['join']['table'], $values['join']['alias'], $values['join']['on']);
|
||||
}
|
||||
$arguments = isset($values['arguments']) ? $values['arguments'] : array();
|
||||
$arguments = isset($values['arguments']) ? $values['arguments'] : [];
|
||||
$query->addScore($values['score'], $arguments, $node_rank);
|
||||
}
|
||||
}
|
||||
|
@ -426,15 +426,15 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
// per cron run.
|
||||
$limit = (int) $this->searchSettings->get('index.cron_limit');
|
||||
|
||||
$query = db_select('node', 'n', array('target' => 'replica'));
|
||||
$query = db_select('node', 'n', ['target' => 'replica']);
|
||||
$query->addField('n', 'nid');
|
||||
$query->leftJoin('search_dataset', 'sd', 'sd.sid = n.nid AND sd.type = :type', array(':type' => $this->getPluginId()));
|
||||
$query->leftJoin('search_dataset', 'sd', 'sd.sid = n.nid AND sd.type = :type', [':type' => $this->getPluginId()]);
|
||||
$query->addExpression('CASE MAX(sd.reindex) WHEN NULL THEN 0 ELSE 1 END', 'ex');
|
||||
$query->addExpression('MAX(sd.reindex)', 'ex2');
|
||||
$query->condition(
|
||||
$query->orConditionGroup()
|
||||
->where('sd.sid IS NULL')
|
||||
->condition('sd.reindex', 0, '<>')
|
||||
->where('sd.sid IS NULL')
|
||||
->condition('sd.reindex', 0, '<>')
|
||||
);
|
||||
$query->orderBy('ex', 'DESC')
|
||||
->orderBy('ex2')
|
||||
|
@ -513,9 +513,9 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
*/
|
||||
public function indexStatus() {
|
||||
$total = $this->database->query('SELECT COUNT(*) FROM {node}')->fetchField();
|
||||
$remaining = $this->database->query("SELECT COUNT(DISTINCT n.nid) FROM {node} n LEFT JOIN {search_dataset} sd ON sd.sid = n.nid AND sd.type = :type WHERE sd.sid IS NULL OR sd.reindex <> 0", array(':type' => $this->getPluginId()))->fetchField();
|
||||
$remaining = $this->database->query("SELECT COUNT(DISTINCT n.nid) FROM {node} n LEFT JOIN {search_dataset} sd ON sd.sid = n.nid AND sd.type = :type WHERE sd.sid IS NULL OR sd.reindex <> 0", [':type' => $this->getPluginId()])->fetchField();
|
||||
|
||||
return array('remaining' => $remaining, 'total' => $total);
|
||||
return ['remaining' => $remaining, 'total' => $total];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -526,100 +526,100 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
$keys = $this->getKeywords();
|
||||
$used_advanced = !empty($parameters[self::ADVANCED_FORM]);
|
||||
if ($used_advanced) {
|
||||
$f = isset($parameters['f']) ? (array) $parameters['f'] : array();
|
||||
$f = isset($parameters['f']) ? (array) $parameters['f'] : [];
|
||||
$defaults = $this->parseAdvancedDefaults($f, $keys);
|
||||
}
|
||||
else {
|
||||
$defaults = array('keys' => $keys);
|
||||
$defaults = ['keys' => $keys];
|
||||
}
|
||||
|
||||
$form['basic']['keys']['#default_value'] = $defaults['keys'];
|
||||
|
||||
// Add advanced search keyword-related boxes.
|
||||
$form['advanced'] = array(
|
||||
$form['advanced'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Advanced search'),
|
||||
'#attributes' => array('class' => array('search-advanced')),
|
||||
'#attributes' => ['class' => ['search-advanced']],
|
||||
'#access' => $this->account && $this->account->hasPermission('use advanced search'),
|
||||
'#open' => $used_advanced,
|
||||
);
|
||||
$form['advanced']['keywords-fieldset'] = array(
|
||||
];
|
||||
$form['advanced']['keywords-fieldset'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Keywords'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['advanced']['keywords'] = array(
|
||||
$form['advanced']['keywords'] = [
|
||||
'#prefix' => '<div class="criterion">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
|
||||
$form['advanced']['keywords-fieldset']['keywords']['or'] = array(
|
||||
$form['advanced']['keywords-fieldset']['keywords']['or'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Containing any of the words'),
|
||||
'#size' => 30,
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => isset($defaults['or']) ? $defaults['or'] : '',
|
||||
);
|
||||
];
|
||||
|
||||
$form['advanced']['keywords-fieldset']['keywords']['phrase'] = array(
|
||||
$form['advanced']['keywords-fieldset']['keywords']['phrase'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Containing the phrase'),
|
||||
'#size' => 30,
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => isset($defaults['phrase']) ? $defaults['phrase'] : '',
|
||||
);
|
||||
];
|
||||
|
||||
$form['advanced']['keywords-fieldset']['keywords']['negative'] = array(
|
||||
$form['advanced']['keywords-fieldset']['keywords']['negative'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Containing none of the words'),
|
||||
'#size' => 30,
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => isset($defaults['negative']) ? $defaults['negative'] : '',
|
||||
);
|
||||
];
|
||||
|
||||
// Add node types.
|
||||
$types = array_map(array('\Drupal\Component\Utility\Html', 'escape'), node_type_get_names());
|
||||
$form['advanced']['types-fieldset'] = array(
|
||||
$types = array_map(['\Drupal\Component\Utility\Html', 'escape'], node_type_get_names());
|
||||
$form['advanced']['types-fieldset'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Types'),
|
||||
);
|
||||
$form['advanced']['types-fieldset']['type'] = array(
|
||||
];
|
||||
$form['advanced']['types-fieldset']['type'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Only of the type(s)'),
|
||||
'#prefix' => '<div class="criterion">',
|
||||
'#suffix' => '</div>',
|
||||
'#options' => $types,
|
||||
'#default_value' => isset($defaults['type']) ? $defaults['type'] : array(),
|
||||
);
|
||||
'#default_value' => isset($defaults['type']) ? $defaults['type'] : [],
|
||||
];
|
||||
|
||||
$form['advanced']['submit'] = array(
|
||||
$form['advanced']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Advanced search'),
|
||||
'#prefix' => '<div class="action">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => 100,
|
||||
);
|
||||
];
|
||||
|
||||
// Add languages.
|
||||
$language_options = array();
|
||||
$language_options = [];
|
||||
$language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
|
||||
foreach ($language_list as $langcode => $language) {
|
||||
// Make locked languages appear special in the list.
|
||||
$language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName();
|
||||
$language_options[$langcode] = $language->isLocked() ? t('- @name -', ['@name' => $language->getName()]) : $language->getName();
|
||||
}
|
||||
if (count($language_options) > 1) {
|
||||
$form['advanced']['lang-fieldset'] = array(
|
||||
$form['advanced']['lang-fieldset'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Languages'),
|
||||
);
|
||||
$form['advanced']['lang-fieldset']['language'] = array(
|
||||
];
|
||||
$form['advanced']['lang-fieldset']['language'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Languages'),
|
||||
'#prefix' => '<div class="criterion">',
|
||||
'#suffix' => '</div>',
|
||||
'#options' => $language_options,
|
||||
'#default_value' => isset($defaults['language']) ? $defaults['language'] : array(),
|
||||
);
|
||||
'#default_value' => isset($defaults['language']) ? $defaults['language'] : [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -633,7 +633,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
$advanced = FALSE;
|
||||
|
||||
// Collect extra filters.
|
||||
$filters = array();
|
||||
$filters = [];
|
||||
if ($form_state->hasValue('type') && is_array($form_state->getValue('type'))) {
|
||||
// Retrieve selected types - Form API sets the value of unselected
|
||||
// checkboxes to 0.
|
||||
|
@ -680,7 +680,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
// Put the keywords and advanced parameters into GET parameters. Make sure
|
||||
// to put keywords into the query even if it is empty, because the page
|
||||
// controller uses that to decide it's time to check for search results.
|
||||
$query = array('keys' => $keys);
|
||||
$query = ['keys' => $keys];
|
||||
if ($filters) {
|
||||
$query['f'] = $filters;
|
||||
}
|
||||
|
@ -707,13 +707,13 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
* a modified 'keys' element for the bare search keywords.
|
||||
*/
|
||||
protected function parseAdvancedDefaults($f, $keys) {
|
||||
$defaults = array();
|
||||
$defaults = [];
|
||||
|
||||
// Split out the advanced search parameters.
|
||||
foreach ($f as $advanced) {
|
||||
list($key, $value) = explode(':', $advanced, 2);
|
||||
if (!isset($defaults[$key])) {
|
||||
$defaults[$key] = array();
|
||||
$defaults[$key] = [];
|
||||
}
|
||||
$defaults[$key][] = $value;
|
||||
}
|
||||
|
@ -721,7 +721,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
// Split out the negative, phrase, and OR parts of keywords.
|
||||
|
||||
// For phrases, the form only supports one phrase.
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
$keys = ' ' . $keys . ' ';
|
||||
if (preg_match('/ "([^"]+)" /', $keys, $matches)) {
|
||||
$keys = str_replace($matches[0], ' ', $keys);
|
||||
|
@ -764,9 +764,9 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
$configuration = array(
|
||||
'rankings' => array(),
|
||||
);
|
||||
$configuration = [
|
||||
'rankings' => [],
|
||||
];
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
|
@ -775,34 +775,34 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
|
|||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
// Output form for defining rank factor weights.
|
||||
$form['content_ranking'] = array(
|
||||
$form['content_ranking'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Content ranking'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['content_ranking']['info'] = array(
|
||||
];
|
||||
$form['content_ranking']['info'] = [
|
||||
'#markup' => '<p><em>' . $this->t('Influence is a numeric multiplier used in ordering search results. A higher number means the corresponding factor has more influence on search results; zero means the factor is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em></p>'
|
||||
);
|
||||
];
|
||||
// Prepare table.
|
||||
$header = [$this->t('Factor'), $this->t('Influence')];
|
||||
$form['content_ranking']['rankings'] = array(
|
||||
$form['content_ranking']['rankings'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
);
|
||||
];
|
||||
|
||||
// Note: reversed to reflect that higher number = higher ranking.
|
||||
$range = range(0, 10);
|
||||
$options = array_combine($range, $range);
|
||||
foreach ($this->getRankings() as $var => $values) {
|
||||
$form['content_ranking']['rankings'][$var]['name'] = array(
|
||||
$form['content_ranking']['rankings'][$var]['name'] = [
|
||||
'#markup' => $values['title'],
|
||||
);
|
||||
$form['content_ranking']['rankings'][$var]['value'] = array(
|
||||
];
|
||||
$form['content_ranking']['rankings'][$var]['value'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#attributes' => ['aria-label' => $this->t("Influence of '@title'", ['@title' => $values['title']])],
|
||||
'#default_value' => isset($this->configuration['rankings'][$var]) ? $this->configuration['rankings'][$var] : 0,
|
||||
);
|
||||
];
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -90,8 +90,18 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
return $this->derivatives;
|
||||
}
|
||||
|
||||
$node_types = static::getSourcePlugin('d6_node_type');
|
||||
try {
|
||||
$node_types->checkRequirements();
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// If the d6_node_type requirements failed, that means we do not have a
|
||||
// Drupal source database configured - there is nothing to generate.
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
// Read all CCK field instance definitions in the source database.
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
try {
|
||||
$source_plugin = static::getSourcePlugin('d6_field_instance');
|
||||
$source_plugin->checkRequirements();
|
||||
|
@ -107,7 +117,7 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
}
|
||||
|
||||
try {
|
||||
foreach (static::getSourcePlugin('d6_node_type') as $row) {
|
||||
foreach ($node_types as $row) {
|
||||
$node_type = $row->getSourceProperty('type');
|
||||
$values = $base_plugin_definition;
|
||||
|
||||
|
|
|
@ -38,6 +38,13 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
*/
|
||||
protected $cckPluginManager;
|
||||
|
||||
/**
|
||||
* Whether or not to include translations.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $includeTranslations;
|
||||
|
||||
/**
|
||||
* D7NodeDeriver constructor.
|
||||
*
|
||||
|
@ -45,19 +52,24 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
* The base plugin ID for the plugin ID.
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager
|
||||
* The CCK plugin manager.
|
||||
* @param bool $translations
|
||||
* Whether or not to include translations.
|
||||
*/
|
||||
public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager) {
|
||||
public function __construct($base_plugin_id, MigrateCckFieldPluginManagerInterface $cck_manager, $translations) {
|
||||
$this->basePluginId = $base_plugin_id;
|
||||
$this->cckPluginManager = $cck_manager;
|
||||
$this->includeTranslations = $translations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
// Translations don't make sense unless we have content_translation.
|
||||
return new static(
|
||||
$base_plugin_id,
|
||||
$container->get('plugin.manager.migrate.cckfield')
|
||||
$container->get('plugin.manager.migrate.cckfield'),
|
||||
$container->get('module_handler')->moduleExists('content_translation')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -65,6 +77,21 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
if (in_array('translation', $base_plugin_definition['migration_tags']) && !$this->includeTranslations) {
|
||||
// Refuse to generate anything.
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
$node_types = static::getSourcePlugin('d7_node_type');
|
||||
try {
|
||||
$node_types->checkRequirements();
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// If the d7_node_type requirements failed, that means we do not have a
|
||||
// Drupal source database configured - there is nothing to generate.
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
$fields = [];
|
||||
try {
|
||||
$source_plugin = static::getSourcePlugin('d7_field_instance');
|
||||
|
@ -84,7 +111,7 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
}
|
||||
|
||||
try {
|
||||
foreach (static::getSourcePlugin('d7_node_type') as $row) {
|
||||
foreach ($node_types as $row) {
|
||||
$node_type = $row->getSourceProperty('type');
|
||||
$values = $base_plugin_definition;
|
||||
|
||||
|
@ -95,6 +122,13 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
$values['source']['node_type'] = $node_type;
|
||||
$values['destination']['default_bundle'] = $node_type;
|
||||
|
||||
// If this migration is based on the d7_node_revision migration or
|
||||
// is for translations of nodes, it should explicitly depend on the
|
||||
// corresponding d7_node variant.
|
||||
if ($base_plugin_definition['id'] == ['d7_node_revision'] || in_array('translation', $base_plugin_definition['migration_tags'])) {
|
||||
$values['migration_dependencies']['required'][] = 'd7_node:' . $node_type;
|
||||
}
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
|
||||
if (isset($fields[$node_type])) {
|
||||
foreach ($fields[$node_type] as $field_name => $info) {
|
||||
|
@ -121,7 +155,6 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
|
|||
// MigrationPluginManager gathers up the migration definitions but we do
|
||||
// not actually have a Drupal 7 source database.
|
||||
}
|
||||
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class EntityNodeType extends EntityConfigBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$entity_ids = parent::import($row, $old_destination_id_values);
|
||||
if ($row->getDestinationProperty('create_body')) {
|
||||
$node_type = $this->storage->load(reset($entity_ids));
|
||||
|
|
|
@ -22,7 +22,7 @@ class NodeUpdate7008 extends ProcessPluginBase {
|
|||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if ($value === 'administer nodes') {
|
||||
return array($value, 'access content overview');
|
||||
return [$value, 'access content overview'];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class Node extends DrupalSqlBase {
|
|||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
$this->handleTranslations($query);
|
||||
|
||||
$query->fields('n', array(
|
||||
$query->fields('n', [
|
||||
'nid',
|
||||
'type',
|
||||
'language',
|
||||
|
@ -90,8 +90,8 @@ class Node extends DrupalSqlBase {
|
|||
'sticky',
|
||||
'tnid',
|
||||
'translate',
|
||||
))
|
||||
->fields('nr', array(
|
||||
])
|
||||
->fields('nr', [
|
||||
'title',
|
||||
'body',
|
||||
'teaser',
|
||||
|
@ -99,7 +99,7 @@ class Node extends DrupalSqlBase {
|
|||
'timestamp',
|
||||
'format',
|
||||
'vid',
|
||||
));
|
||||
]);
|
||||
$query->addField('n', 'uid', 'node_uid');
|
||||
$query->addField('nr', 'uid', 'revision_uid');
|
||||
|
||||
|
@ -129,7 +129,7 @@ class Node extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'nid' => $this->t('Node ID'),
|
||||
'type' => $this->t('Type'),
|
||||
'title' => $this->t('Title'),
|
||||
|
@ -147,7 +147,7 @@ class Node extends DrupalSqlBase {
|
|||
'language' => $this->t('Language (fr, en, ...)'),
|
||||
'tnid' => $this->t('The translation set id for this node'),
|
||||
'timestamp' => $this->t('The timestamp the latest revision of this node was created.'),
|
||||
);
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ class NodeRevision extends Node {
|
|||
*/
|
||||
public function fields() {
|
||||
// Use all the node fields plus the vid that identifies the version.
|
||||
return parent::fields() + array(
|
||||
return parent::fields() + [
|
||||
'vid' => t('The primary identifier for this version.'),
|
||||
'log' => $this->t('Revision Log message'),
|
||||
'timestamp' => $this->t('Revision timestamp'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ class NodeType extends DrupalSqlBase {
|
|||
*/
|
||||
public function query() {
|
||||
return $this->select('node_type', 't')
|
||||
->fields('t', array(
|
||||
->fields('t', [
|
||||
'type',
|
||||
'name',
|
||||
'module',
|
||||
|
@ -54,7 +54,7 @@ class NodeType extends DrupalSqlBase {
|
|||
'modified',
|
||||
'locked',
|
||||
'orig_type',
|
||||
))
|
||||
])
|
||||
->orderBy('t.type');
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ class NodeType extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'type' => $this->t('Machine name of the node type.'),
|
||||
'name' => $this->t('Human name of the node type.'),
|
||||
'module' => $this->t('The module providing the node type.'),
|
||||
|
@ -77,7 +77,7 @@ class NodeType extends DrupalSqlBase {
|
|||
'locked' => $this->t('Flag.'),
|
||||
'orig_type' => $this->t('The original type.'),
|
||||
'teaser_length' => $this->t('Teaser length'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,7 +86,7 @@ class NodeType extends DrupalSqlBase {
|
|||
protected function initializeIterator() {
|
||||
$this->teaserLength = $this->variableGet('teaser_length', 600);
|
||||
$this->nodePreview = $this->variableGet('node_preview', 0);
|
||||
$this->themeSettings = $this->variableGet('theme_settings', array());
|
||||
$this->themeSettings = $this->variableGet('theme_settings', []);
|
||||
return parent::initializeIterator();
|
||||
}
|
||||
|
||||
|
@ -98,9 +98,9 @@ class NodeType extends DrupalSqlBase {
|
|||
$row->setSourceProperty('node_preview', $this->nodePreview);
|
||||
|
||||
$type = $row->getSourceProperty('type');
|
||||
$source_options = $this->variableGet('node_options_' . $type, array('promote', 'sticky'));
|
||||
$options = array();
|
||||
foreach (array('promote', 'sticky', 'status', 'revision') as $item) {
|
||||
$source_options = $this->variableGet('node_options_' . $type, ['promote', 'sticky']);
|
||||
$options = [];
|
||||
foreach (['promote', 'sticky', 'status', 'revision'] as $item) {
|
||||
$options[$item] = in_array($item, $source_options);
|
||||
}
|
||||
$row->setSourceProperty('options', $options);
|
||||
|
|
|
@ -16,12 +16,15 @@ class ViewMode extends ViewModeBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
$result = $this->prepareQuery()->execute();
|
||||
while ($field_row = $result->fetchAssoc()) {
|
||||
$field_row['display_settings'] = unserialize($field_row['display_settings']);
|
||||
foreach ($this->getViewModes() as $view_mode) {
|
||||
if (isset($field_row['display_settings'][$view_mode]) && empty($field_row['display_settings'][$view_mode]['exclude'])) {
|
||||
// Append to the return value if the row has display settings for this
|
||||
// view mode and the view mode is neither hidden nor excluded.
|
||||
// @see \Drupal\field\Plugin\migrate\source\d6\FieldInstancePerViewMode::initializeIterator()
|
||||
if (isset($field_row['display_settings'][$view_mode]) && $field_row['display_settings'][$view_mode]['format'] != 'hidden' && empty($field_row['display_settings'][$view_mode]['exclude'])) {
|
||||
if (!isset($rows[$view_mode])) {
|
||||
$rows[$view_mode]['entity_type'] = 'node';
|
||||
$rows[$view_mode]['view_mode'] = $view_mode;
|
||||
|
@ -38,9 +41,9 @@ class ViewMode extends ViewModeBase {
|
|||
*/
|
||||
public function query() {
|
||||
$query = $this->select('content_node_field_instance', 'cnfi')
|
||||
->fields('cnfi', array(
|
||||
->fields('cnfi', [
|
||||
'display_settings',
|
||||
));
|
||||
]);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
@ -49,9 +52,9 @@ class ViewMode extends ViewModeBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'display_settings' => $this->t('Serialize data with display settings.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ abstract class ViewModeBase extends DrupalSqlBase {
|
|||
* The view mode names.
|
||||
*/
|
||||
public function getViewModes() {
|
||||
return array(
|
||||
return [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
|
@ -42,7 +42,7 @@ abstract class ViewModeBase extends DrupalSqlBase {
|
|||
5,
|
||||
'teaser',
|
||||
'full',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
|
||||
namespace Drupal\node\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandler;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Drupal 7 node source from database.
|
||||
|
@ -14,6 +21,35 @@ use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
|||
* )
|
||||
*/
|
||||
class Node extends FieldableEntity {
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('state'),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('module_handler')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The join options between the node and the node_revisions table.
|
||||
|
@ -26,7 +62,7 @@ class Node extends FieldableEntity {
|
|||
public function query() {
|
||||
// Select node in its last revision.
|
||||
$query = $this->select('node_revision', 'nr')
|
||||
->fields('n', array(
|
||||
->fields('n', [
|
||||
'nid',
|
||||
'type',
|
||||
'language',
|
||||
|
@ -38,17 +74,25 @@ class Node extends FieldableEntity {
|
|||
'sticky',
|
||||
'tnid',
|
||||
'translate',
|
||||
))
|
||||
->fields('nr', array(
|
||||
])
|
||||
->fields('nr', [
|
||||
'vid',
|
||||
'title',
|
||||
'log',
|
||||
'timestamp',
|
||||
));
|
||||
]);
|
||||
$query->addField('n', 'uid', 'node_uid');
|
||||
$query->addField('nr', 'uid', 'revision_uid');
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
|
||||
// If the content_translation module is enabled, get the source langcode
|
||||
// to fill the content_translation_source field.
|
||||
if ($this->moduleHandler->moduleExists('content_translation')) {
|
||||
$query->leftJoin('node', 'nt', 'n.tnid = nt.nid');
|
||||
$query->addField('nt', 'language', 'source_langcode');
|
||||
}
|
||||
$this->handleTranslations($query);
|
||||
|
||||
if (isset($this->configuration['node_type'])) {
|
||||
$query->condition('n.type', $this->configuration['node_type']);
|
||||
}
|
||||
|
@ -66,6 +110,11 @@ class Node extends FieldableEntity {
|
|||
$vid = $row->getSourceProperty('vid');
|
||||
$row->setSourceProperty($field, $this->getFieldValues('node', $field, $nid, $vid));
|
||||
}
|
||||
|
||||
// Make sure we always have a translation set.
|
||||
if ($row->getSourceProperty('tnid') == 0) {
|
||||
$row->setSourceProperty('tnid', $row->getSourceProperty('nid'));
|
||||
}
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
|
@ -73,7 +122,7 @@ class Node extends FieldableEntity {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'nid' => $this->t('Node ID'),
|
||||
'type' => $this->t('Type'),
|
||||
'title' => $this->t('Title'),
|
||||
|
@ -88,7 +137,7 @@ class Node extends FieldableEntity {
|
|||
'language' => $this->t('Language (fr, en, ...)'),
|
||||
'tnid' => $this->t('The translation set id for this node'),
|
||||
'timestamp' => $this->t('The timestamp the latest revision of this node was created.'),
|
||||
);
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
@ -101,4 +150,22 @@ class Node extends FieldableEntity {
|
|||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt our query for translations.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Query\SelectInterface $query
|
||||
* The generated query.
|
||||
*/
|
||||
protected function handleTranslations(SelectInterface $query) {
|
||||
// Check whether or not we want translations.
|
||||
if (empty($this->configuration['translations'])) {
|
||||
// No translations: Yield untranslated nodes, or default translations.
|
||||
$query->where('n.tnid = 0 OR n.tnid = n.nid');
|
||||
}
|
||||
else {
|
||||
// Translations: Yield only non-default translations.
|
||||
$query->where('n.tnid <> 0 AND n.tnid <> n.nid');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@ class NodeRevision extends Node {
|
|||
*/
|
||||
public function fields() {
|
||||
// Use all the node fields plus the vid that identifies the version.
|
||||
return parent::fields() + array(
|
||||
return parent::fields() + [
|
||||
'vid' => t('The primary identifier for this version.'),
|
||||
'log' => $this->t('Revision Log message'),
|
||||
'timestamp' => $this->t('Revision timestamp'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ class NodeType extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'type' => $this->t('Machine name of the node type.'),
|
||||
'name' => $this->t('Human name of the node type.'),
|
||||
'description' => $this->t('Description of the node type.'),
|
||||
|
@ -53,7 +53,7 @@ class NodeType extends DrupalSqlBase {
|
|||
'locked' => $this->t('Flag.'),
|
||||
'orig_type' => $this->t('The original type.'),
|
||||
'teaser_length' => $this->t('Teaser length'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,9 +73,9 @@ class NodeType extends DrupalSqlBase {
|
|||
$row->setSourceProperty('node_preview', $this->nodePreview);
|
||||
|
||||
$type = $row->getSourceProperty('type');
|
||||
$source_options = $this->variableGet('node_options_' . $type, array('promote', 'sticky'));
|
||||
$options = array();
|
||||
foreach (array('promote', 'sticky', 'status', 'revision') as $item) {
|
||||
$source_options = $this->variableGet('node_options_' . $type, ['promote', 'sticky']);
|
||||
$options = [];
|
||||
foreach (['promote', 'sticky', 'status', 'revision'] as $item) {
|
||||
$options[$item] = in_array($item, $source_options);
|
||||
}
|
||||
$row->setSourceProperty('options', $options);
|
||||
|
@ -86,7 +86,7 @@ class NodeType extends DrupalSqlBase {
|
|||
if ($this->moduleExists('field')) {
|
||||
// Find body field for this node type.
|
||||
$body = $this->select('field_config_instance', 'fci')
|
||||
->fields('fci', array('data'))
|
||||
->fields('fci', ['data'])
|
||||
->condition('entity_type', 'node')
|
||||
->condition('bundle', $row->getSourceProperty('type'))
|
||||
->condition('field_name', 'body')
|
||||
|
|
|
@ -59,19 +59,19 @@ class ListingEmpty extends AreaPluginBase {
|
|||
public function render($empty = FALSE) {
|
||||
$account = \Drupal::currentUser();
|
||||
if (!$empty || !empty($this->options['empty'])) {
|
||||
$element = array(
|
||||
$element = [
|
||||
'#theme' => 'links',
|
||||
'#links' => array(
|
||||
array(
|
||||
'#links' => [
|
||||
[
|
||||
'url' => Url::fromRoute('node.add_page'),
|
||||
'title' => $this->t('Add content'),
|
||||
),
|
||||
),
|
||||
'#access' => $this->accessManager->checkNamedRoute('node.add_page', array(), $account),
|
||||
);
|
||||
],
|
||||
],
|
||||
'#access' => $this->accessManager->checkNamedRoute('node.add_page', [], $account),
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class Nid extends NumericArgument {
|
|||
* Override the behavior of title(). Get the title of the node.
|
||||
*/
|
||||
public function titleQuery() {
|
||||
$titles = array();
|
||||
$titles = [];
|
||||
|
||||
$nodes = $this->nodeStorage->loadMultiple($this->value);
|
||||
foreach ($nodes as $node) {
|
||||
|
|
|
@ -63,11 +63,11 @@ class Type extends StringArgument {
|
|||
* Override the behavior of title(). Get the user friendly version of the
|
||||
* node type.
|
||||
*/
|
||||
function title() {
|
||||
public function title() {
|
||||
return $this->node_type($this->argument);
|
||||
}
|
||||
|
||||
function node_type($type_name) {
|
||||
public function node_type($type_name) {
|
||||
$type = $this->nodeTypeStorage->load($type_name);
|
||||
$output = $type ? $type->label() : $this->t('Unknown content type');
|
||||
return $output;
|
||||
|
|
|
@ -15,7 +15,7 @@ class UidRevision extends Uid {
|
|||
public function query($group_by = FALSE) {
|
||||
$this->ensureMyTable();
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->addWhereExpression(0, "$this->tableAlias.revision_uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nfr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", array($placeholder => $this->argument));
|
||||
$this->query->addWhereExpression(0, "$this->tableAlias.revision_uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nfr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $this->argument]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,10 +66,10 @@ class Vid extends NumericArgument {
|
|||
* Override the behavior of title(). Get the title of the revision.
|
||||
*/
|
||||
public function titleQuery() {
|
||||
$titles = array();
|
||||
$titles = [];
|
||||
|
||||
$results = $this->database->query('SELECT nr.vid, nr.nid, npr.title FROM {node_revision} nr WHERE nr.vid IN ( :vids[] )', array(':vids[]' => $this->value))->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
|
||||
$nids = array();
|
||||
$results = $this->database->query('SELECT nr.vid, nr.nid, npr.title FROM {node_revision} nr WHERE nr.vid IN ( :vids[] )', [':vids[]' => $this->value])->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
|
||||
$nids = [];
|
||||
foreach ($results as $result) {
|
||||
$nids[] = $result['nid'];
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class Node extends FieldPluginBase {
|
|||
|
||||
// Don't add the additional fields to groupby
|
||||
if (!empty($this->options['link_to_node'])) {
|
||||
$this->additional_fields['nid'] = array('table' => 'node_field_data', 'field' => 'nid');
|
||||
$this->additional_fields['nid'] = ['table' => 'node_field_data', 'field' => 'nid'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ class Node extends FieldPluginBase {
|
|||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['link_to_node'] = array('default' => isset($this->definition['link_to_node default']) ? $this->definition['link_to_node default'] : FALSE);
|
||||
$options['link_to_node'] = ['default' => isset($this->definition['link_to_node default']) ? $this->definition['link_to_node default'] : FALSE];
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
@ -45,12 +45,12 @@ class Node extends FieldPluginBase {
|
|||
* Provide link to node option
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
$form['link_to_node'] = array(
|
||||
$form['link_to_node'] = [
|
||||
'#title' => $this->t('Link this field to the original piece of content'),
|
||||
'#description' => $this->t("Enable to override this field's links."),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['link_to_node']),
|
||||
);
|
||||
];
|
||||
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class Path extends FieldPluginBase {
|
|||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['absolute'] = array('default' => FALSE);
|
||||
$options['absolute'] = ['default' => FALSE];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ class Path extends FieldPluginBase {
|
|||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
$form['absolute'] = array(
|
||||
$form['absolute'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Use absolute link (begins with "http://")'),
|
||||
'#default_value' => $this->options['absolute'],
|
||||
'#description' => $this->t('Enable this option to output an absolute link. Required if you want to use the path as a link destination (as in "output this field as a link" above).'),
|
||||
'#fieldset' => 'alter',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,9 +63,9 @@ class Path extends FieldPluginBase {
|
|||
*/
|
||||
public function render(ResultRow $values) {
|
||||
$nid = $this->getValue($values, 'nid');
|
||||
return array(
|
||||
return [
|
||||
'#markup' => \Drupal::url('entity.node.canonical', ['node' => $nid], ['absolute' => $this->options['absolute']]),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class UidRevision extends Name {
|
|||
$args = array_values($this->value);
|
||||
|
||||
$this->query->addWhereExpression($this->options['group'], "$this->tableAlias.uid IN($placeholder) OR
|
||||
((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nr.revision_uid IN ($placeholder) AND nr.nid = $this->tableAlias.nid) > 0)", array($placeholder => $args),
|
||||
((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nr.revision_uid IN ($placeholder) AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $args],
|
||||
$args);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class Rss extends RssPluginBase {
|
|||
public $base_field = 'nid';
|
||||
|
||||
// Stores the nodes loaded with preRender.
|
||||
public $nodes = array();
|
||||
public $nodes = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -74,7 +74,7 @@ class Rss extends RssPluginBase {
|
|||
}
|
||||
|
||||
public function preRender($values) {
|
||||
$nids = array();
|
||||
$nids = [];
|
||||
foreach ($values as $row) {
|
||||
$nids[] = $row->{$this->field_alias};
|
||||
}
|
||||
|
@ -103,23 +103,23 @@ class Rss extends RssPluginBase {
|
|||
return;
|
||||
}
|
||||
|
||||
$node->link = $node->url('canonical', array('absolute' => TRUE));
|
||||
$node->rss_namespaces = array();
|
||||
$node->rss_elements = array(
|
||||
array(
|
||||
$node->link = $node->url('canonical', ['absolute' => TRUE]);
|
||||
$node->rss_namespaces = [];
|
||||
$node->rss_elements = [
|
||||
[
|
||||
'key' => 'pubDate',
|
||||
'value' => gmdate('r', $node->getCreatedTime()),
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'key' => 'dc:creator',
|
||||
'value' => $node->getOwner()->getDisplayName(),
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'key' => 'guid',
|
||||
'value' => $node->id() . ' at ' . $base_url,
|
||||
'attributes' => array('isPermaLink' => 'false'),
|
||||
),
|
||||
);
|
||||
'attributes' => ['isPermaLink' => 'false'],
|
||||
],
|
||||
];
|
||||
|
||||
// The node gets built and modules add to or modify $node->rss_elements
|
||||
// and $node->rss_namespaces.
|
||||
|
@ -135,7 +135,7 @@ class Rss extends RssPluginBase {
|
|||
elseif (function_exists('rdf_get_namespaces')) {
|
||||
// Merge RDF namespaces in the XML namespaces in case they are used
|
||||
// further in the RSS content.
|
||||
$xml_rdf_namespaces = array();
|
||||
$xml_rdf_namespaces = [];
|
||||
foreach (rdf_get_namespaces() as $prefix => $uri) {
|
||||
$xml_rdf_namespaces['xmlns:' . $prefix] = $uri;
|
||||
}
|
||||
|
@ -153,12 +153,12 @@ class Rss extends RssPluginBase {
|
|||
// template_preprocess_views_view_row_rss() can still access it.
|
||||
$item->elements = &$node->rss_elements;
|
||||
$item->nid = $node->id();
|
||||
$build = array(
|
||||
$build = [
|
||||
'#theme' => $this->themeFunctions(),
|
||||
'#view' => $this->view,
|
||||
'#options' => $this->options,
|
||||
'#row' => $item,
|
||||
);
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
|
|
@ -28,16 +28,16 @@ class Node extends WizardPluginBase {
|
|||
/**
|
||||
* Set default values for the filters.
|
||||
*/
|
||||
protected $filters = array(
|
||||
'status' => array(
|
||||
protected $filters = [
|
||||
'status' => [
|
||||
'value' => TRUE,
|
||||
'table' => 'node_field_data',
|
||||
'field' => 'status',
|
||||
'plugin_id' => 'boolean',
|
||||
'entity_type' => 'node',
|
||||
'entity_field' => 'status',
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::getAvailableSorts().
|
||||
|
@ -48,16 +48,16 @@ class Node extends WizardPluginBase {
|
|||
*/
|
||||
public function getAvailableSorts() {
|
||||
// You can't execute functions in properties, so override the method
|
||||
return array(
|
||||
return [
|
||||
'node_field_data-title:ASC' => $this->t('Title')
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function rowStyleOptions() {
|
||||
$options = array();
|
||||
$options = [];
|
||||
$options['teasers'] = $this->t('teasers');
|
||||
$options['full_posts'] = $this->t('full posts');
|
||||
$options['titles'] = $this->t('titles');
|
||||
|
@ -110,22 +110,22 @@ class Node extends WizardPluginBase {
|
|||
protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state) {
|
||||
$filters = parent::defaultDisplayFiltersUser($form, $form_state);
|
||||
|
||||
$tids = array();
|
||||
if ($values = $form_state->getValue(array('show', 'tagged_with'))) {
|
||||
$tids = [];
|
||||
if ($values = $form_state->getValue(['show', 'tagged_with'])) {
|
||||
foreach ($values as $value) {
|
||||
$tids[] = $value['target_id'];
|
||||
}
|
||||
}
|
||||
if (!empty($tids)) {
|
||||
$vid = reset($form['displays']['show']['tagged_with']['#selection_settings']['target_bundles']);
|
||||
$filters['tid'] = array(
|
||||
$filters['tid'] = [
|
||||
'id' => 'tid',
|
||||
'table' => 'taxonomy_index',
|
||||
'field' => 'tid',
|
||||
'value' => $tids,
|
||||
'vid' => $vid,
|
||||
'plugin_id' => 'taxonomy_index_tid',
|
||||
);
|
||||
];
|
||||
// If the user entered more than one valid term in the autocomplete
|
||||
// field, they probably intended both of them to be applied.
|
||||
if (count($tids) > 1) {
|
||||
|
@ -144,8 +144,8 @@ class Node extends WizardPluginBase {
|
|||
*/
|
||||
protected function pageDisplayOptions(array $form, FormStateInterface $form_state) {
|
||||
$display_options = parent::pageDisplayOptions($form, $form_state);
|
||||
$row_plugin = $form_state->getValue(array('page', 'style', 'row_plugin'));
|
||||
$row_options = $form_state->getValue(array('page', 'style', 'row_options'), array());
|
||||
$row_plugin = $form_state->getValue(['page', 'style', 'row_plugin']);
|
||||
$row_options = $form_state->getValue(['page', 'style', 'row_options'], []);
|
||||
$this->display_options_row($display_options, $row_plugin, $row_options);
|
||||
return $display_options;
|
||||
}
|
||||
|
@ -155,8 +155,8 @@ class Node extends WizardPluginBase {
|
|||
*/
|
||||
protected function blockDisplayOptions(array $form, FormStateInterface $form_state) {
|
||||
$display_options = parent::blockDisplayOptions($form, $form_state);
|
||||
$row_plugin = $form_state->getValue(array('block', 'style', 'row_plugin'));
|
||||
$row_options = $form_state->getValue(array('block', 'style', 'row_options'), array());
|
||||
$row_plugin = $form_state->getValue(['block', 'style', 'row_plugin']);
|
||||
$row_options = $form_state->getValue(['block', 'style', 'row_options'], []);
|
||||
$this->display_options_row($display_options, $row_plugin, $row_options);
|
||||
return $display_options;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ class Node extends WizardPluginBase {
|
|||
parent::buildFilters($form, $form_state);
|
||||
|
||||
if (isset($form['displays']['show']['type'])) {
|
||||
$selected_bundle = static::getSelected($form_state, array('show', 'type'), 'all', $form['displays']['show']['type']);
|
||||
$selected_bundle = static::getSelected($form_state, ['show', 'type'], 'all', $form['displays']['show']['type']);
|
||||
}
|
||||
|
||||
// Add the "tagged with" filter to the view.
|
||||
|
@ -221,9 +221,9 @@ class Node extends WizardPluginBase {
|
|||
// Double check that this is a real bundle before using it (since above
|
||||
// we added a dummy option 'all' to the bundle list on the form).
|
||||
if (isset($selected_bundle) && in_array($selected_bundle, $bundles)) {
|
||||
$bundles = array($selected_bundle);
|
||||
$bundles = [$selected_bundle];
|
||||
}
|
||||
$tag_fields = array();
|
||||
$tag_fields = [];
|
||||
foreach ($bundles as $bundle) {
|
||||
$display = entity_get_form_display($this->entityTypeId, $bundle, 'default');
|
||||
$taxonomy_fields = array_filter(\Drupal::entityManager()->getFieldDefinitions($this->entityTypeId, $bundle), function ($field_definition) {
|
||||
|
@ -253,7 +253,7 @@ class Node extends WizardPluginBase {
|
|||
}
|
||||
// Add the autocomplete textfield to the wizard.
|
||||
$target_bundles = $tag_fields[$tag_field_name]->getSetting('handler_settings')['target_bundles'];
|
||||
$form['displays']['show']['tagged_with'] = array(
|
||||
$form['displays']['show']['tagged_with'] = [
|
||||
'#type' => 'entity_autocomplete',
|
||||
'#title' => $this->t('tagged with'),
|
||||
'#target_type' => 'taxonomy_term',
|
||||
|
@ -261,7 +261,7 @@ class Node extends WizardPluginBase {
|
|||
'#tags' => TRUE,
|
||||
'#size' => 30,
|
||||
'#maxlength' => 1024,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,16 +27,16 @@ class NodeRevision extends WizardPluginBase {
|
|||
/**
|
||||
* Set default values for the filters.
|
||||
*/
|
||||
protected $filters = array(
|
||||
'status' => array(
|
||||
protected $filters = [
|
||||
'status' => [
|
||||
'value' => TRUE,
|
||||
'table' => 'node_field_revision',
|
||||
'field' => 'status',
|
||||
'plugin_id' => 'boolean',
|
||||
'entity_type' => 'node',
|
||||
'entity_field' => 'status',
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::rowStyleOptions().
|
||||
|
|
|
@ -19,13 +19,13 @@ class RouteSubscriber extends RouteSubscriberBase {
|
|||
// a node listing instead of the path's child links.
|
||||
$route = $collection->get('system.admin_content');
|
||||
if ($route) {
|
||||
$route->setDefaults(array(
|
||||
$route->setDefaults([
|
||||
'_title' => 'Content',
|
||||
'_entity_list' => 'node',
|
||||
));
|
||||
$route->setRequirements(array(
|
||||
]);
|
||||
$route->setRequirements([
|
||||
'_permission' => 'access content overview',
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class NodeAccessBaseTableTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node_access_test', 'views');
|
||||
public static $modules = ['node_access_test', 'views'];
|
||||
|
||||
/**
|
||||
* The installation profile to use with this test.
|
||||
|
@ -83,25 +83,25 @@ class NodeAccessBaseTableTest extends NodeTestBase {
|
|||
* - Test that user 4 can view all content created above.
|
||||
* - Test that user 4 can view all content on taxonomy listing.
|
||||
*/
|
||||
function testNodeAccessBasic() {
|
||||
public function testNodeAccessBasic() {
|
||||
$num_simple_users = 2;
|
||||
$simple_users = array();
|
||||
$simple_users = [];
|
||||
|
||||
// Nodes keyed by uid and nid: $nodes[$uid][$nid] = $is_private;
|
||||
$this->nodesByUser = array();
|
||||
$this->nodesByUser = [];
|
||||
// Titles keyed by nid.
|
||||
$titles = [];
|
||||
// Array of nids marked private.
|
||||
$private_nodes = [];
|
||||
for ($i = 0; $i < $num_simple_users; $i++) {
|
||||
$simple_users[$i] = $this->drupalCreateUser(array('access content', 'create article content'));
|
||||
$simple_users[$i] = $this->drupalCreateUser(['access content', 'create article content']);
|
||||
}
|
||||
foreach ($simple_users as $this->webUser) {
|
||||
$this->drupalLogin($this->webUser);
|
||||
foreach (array(0 => 'Public', 1 => 'Private') as $is_private => $type) {
|
||||
$edit = array(
|
||||
'title[0][value]' => t('@private_public Article created by @user', array('@private_public' => $type, '@user' => $this->webUser->getUsername())),
|
||||
);
|
||||
foreach ([0 => 'Public', 1 => 'Private'] as $is_private => $type) {
|
||||
$edit = [
|
||||
'title[0][value]' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $this->webUser->getUsername()]),
|
||||
];
|
||||
if ($is_private) {
|
||||
$edit['private[0][value]'] = TRUE;
|
||||
$edit['body[0][value]'] = 'private node';
|
||||
|
@ -122,8 +122,8 @@ class NodeAccessBaseTableTest extends NodeTestBase {
|
|||
$this->nodesByUser[$this->webUser->id()][$node->id()] = $is_private;
|
||||
}
|
||||
}
|
||||
$this->publicTid = db_query('SELECT tid FROM {taxonomy_term_field_data} WHERE name = :name AND default_langcode = 1', array(':name' => 'public'))->fetchField();
|
||||
$this->privateTid = db_query('SELECT tid FROM {taxonomy_term_field_data} WHERE name = :name AND default_langcode = 1', array(':name' => 'private'))->fetchField();
|
||||
$this->publicTid = db_query('SELECT tid FROM {taxonomy_term_field_data} WHERE name = :name AND default_langcode = 1', [':name' => 'public'])->fetchField();
|
||||
$this->privateTid = db_query('SELECT tid FROM {taxonomy_term_field_data} WHERE name = :name AND default_langcode = 1', [':name' => 'private'])->fetchField();
|
||||
$this->assertTrue($this->publicTid, 'Public tid was found');
|
||||
$this->assertTrue($this->privateTid, 'Private tid was found');
|
||||
foreach ($simple_users as $this->webUser) {
|
||||
|
@ -138,12 +138,12 @@ class NodeAccessBaseTableTest extends NodeTestBase {
|
|||
else {
|
||||
$should_be_visible = TRUE;
|
||||
}
|
||||
$this->assertResponse($should_be_visible ? 200 : 403, strtr('A %private node by user %uid is %visible for user %current_uid.', array(
|
||||
$this->assertResponse($should_be_visible ? 200 : 403, strtr('A %private node by user %uid is %visible for user %current_uid.', [
|
||||
'%private' => $is_private ? 'private' : 'public',
|
||||
'%uid' => $uid,
|
||||
'%visible' => $should_be_visible ? 'visible' : 'not visible',
|
||||
'%current_uid' => $this->webUser->id(),
|
||||
)));
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ class NodeAccessBaseTableTest extends NodeTestBase {
|
|||
}
|
||||
|
||||
// Now test that a user with 'node test view' permissions can view content.
|
||||
$access_user = $this->drupalCreateUser(array('access content', 'create article content', 'node test view', 'search content'));
|
||||
$access_user = $this->drupalCreateUser(['access content', 'create article content', 'node test view', 'search content']);
|
||||
$this->drupalLogin($access_user);
|
||||
|
||||
foreach ($this->nodesByUser as $private_status) {
|
||||
|
@ -193,7 +193,7 @@ class NodeAccessBaseTableTest extends NodeTestBase {
|
|||
* user's own private nodes should be listed.
|
||||
*/
|
||||
protected function assertTaxonomyPage($is_admin) {
|
||||
foreach (array($this->publicTid, $this->privateTid) as $tid_is_private => $tid) {
|
||||
foreach ([$this->publicTid, $this->privateTid] as $tid_is_private => $tid) {
|
||||
$this->drupalGet("taxonomy/term/$tid");
|
||||
$this->nidsVisible = [];
|
||||
foreach ($this->xpath("//a[text()='Read more']") as $link) {
|
||||
|
@ -211,13 +211,13 @@ class NodeAccessBaseTableTest extends NodeTestBase {
|
|||
if (!$is_admin && $tid_is_private) {
|
||||
$should_be_visible = $should_be_visible && $uid == $this->webUser->id();
|
||||
}
|
||||
$this->assertIdentical(isset($this->nidsVisible[$nid]), $should_be_visible, strtr('A %private node by user %uid is %visible for user %current_uid on the %tid_is_private page.', array(
|
||||
$this->assertIdentical(isset($this->nidsVisible[$nid]), $should_be_visible, strtr('A %private node by user %uid is %visible for user %current_uid on the %tid_is_private page.', [
|
||||
'%private' => $is_private ? 'private' : 'public',
|
||||
'%uid' => $uid,
|
||||
'%visible' => isset($this->nidsVisible[$nid]) ? 'visible' : 'not visible',
|
||||
'%current_uid' => $this->webUser->id(),
|
||||
'%tid_is_private' => $tid_is_private ? 'private' : 'public',
|
||||
)));
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,15 @@ class NodeAccessPagerTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node_access_test', 'comment', 'forum');
|
||||
public static $modules = ['node_access_test', 'comment', 'forum'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
node_access_rebuild();
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
$this->webUser = $this->drupalCreateUser(array('access content', 'access comments', 'node test view'));
|
||||
$this->webUser = $this->drupalCreateUser(['access content', 'access comments', 'node test view']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,16 +41,16 @@ class NodeAccessPagerTest extends WebTestBase {
|
|||
|
||||
// Create 60 comments.
|
||||
for ($i = 0; $i < 60; $i++) {
|
||||
$comment = Comment::create(array(
|
||||
$comment = Comment::create([
|
||||
'entity_id' => $node->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'subject' => $this->randomMachineName(),
|
||||
'comment_body' => array(
|
||||
array('value' => $this->randomMachineName()),
|
||||
),
|
||||
'comment_body' => [
|
||||
['value' => $this->randomMachineName()],
|
||||
],
|
||||
'status' => CommentInterface::PUBLISHED,
|
||||
));
|
||||
]);
|
||||
$comment->save();
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,13 @@ class NodeAccessPagerTest extends WebTestBase {
|
|||
|
||||
// Create 30 nodes.
|
||||
for ($i = 0; $i < 30; $i++) {
|
||||
$this->drupalCreateNode(array(
|
||||
$this->drupalCreateNode([
|
||||
'nid' => NULL,
|
||||
'type' => 'forum',
|
||||
'taxonomy_forums' => array(
|
||||
array('target_id' => $tid),
|
||||
),
|
||||
));
|
||||
'taxonomy_forums' => [
|
||||
['target_id' => $tid],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// View the general discussion forum page. With the default 25 nodes per
|
||||
|
|
|
@ -32,7 +32,7 @@ class NodeAccessRebuildNodeGrantsTest extends NodeTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'access site reports'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer site configuration', 'access administration pages', 'access site reports']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$this->webUser = $this->drupalCreateUser();
|
||||
|
@ -50,10 +50,10 @@ class NodeAccessRebuildNodeGrantsTest extends NodeTestBase {
|
|||
// Create 30 nodes so that _node_access_rebuild_batch_operation() has to run
|
||||
// more than once.
|
||||
for ($i = 0; $i < 30; $i++) {
|
||||
$nodes[] = $this->drupalCreateNode(array(
|
||||
$nodes[] = $this->drupalCreateNode([
|
||||
'uid' => $this->webUser->id(),
|
||||
'private' => [['value' => 1]]
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/** @var \Drupal\node\NodeGrantDatabaseStorageInterface $grant_storage */
|
||||
|
@ -71,7 +71,7 @@ class NodeAccessRebuildNodeGrantsTest extends NodeTestBase {
|
|||
// Rebuild permissions.
|
||||
$this->drupalGet('admin/reports/status');
|
||||
$this->clickLink(t('Rebuild permissions'));
|
||||
$this->drupalPostForm(NULL, array(), t('Rebuild permissions'));
|
||||
$this->drupalPostForm(NULL, [], t('Rebuild permissions'));
|
||||
$this->assertText(t('The content access permissions have been rebuilt.'));
|
||||
|
||||
// Test if the rebuild by user that cannot bypass node access and does not
|
||||
|
@ -107,7 +107,7 @@ class NodeAccessRebuildNodeGrantsTest extends NodeTestBase {
|
|||
// Rebuild permissions.
|
||||
$this->drupalGet('admin/reports/status');
|
||||
$this->clickLink(t('Rebuild permissions'));
|
||||
$this->drupalPostForm(NULL, array(), t('Rebuild permissions'));
|
||||
$this->drupalPostForm(NULL, [], t('Rebuild permissions'));
|
||||
$this->assertText(t('Content permissions have been rebuilt.'));
|
||||
$this->assertNull(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions have been rebuilt');
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class NodeAdminTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('views');
|
||||
public static $modules = ['views'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -51,9 +51,9 @@ class NodeAdminTest extends NodeTestBase {
|
|||
// Remove the "view own unpublished content" permission which is set
|
||||
// by default for authenticated users so we can test this permission
|
||||
// correctly.
|
||||
user_role_revoke_permissions(RoleInterface::AUTHENTICATED_ID, array('view own unpublished content'));
|
||||
user_role_revoke_permissions(RoleInterface::AUTHENTICATED_ID, ['view own unpublished content']);
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access'));
|
||||
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'access content overview', 'administer nodes', 'bypass node access']);
|
||||
$this->baseUser1 = $this->drupalCreateUser(['access content overview']);
|
||||
$this->baseUser2 = $this->drupalCreateUser(['access content overview', 'view own unpublished content']);
|
||||
$this->baseUser3 = $this->drupalCreateUser(['access content overview', 'bypass node access']);
|
||||
|
@ -62,43 +62,43 @@ class NodeAdminTest extends NodeTestBase {
|
|||
/**
|
||||
* Tests that the table sorting works on the content admin pages.
|
||||
*/
|
||||
function testContentAdminSort() {
|
||||
public function testContentAdminSort() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$changed = REQUEST_TIME;
|
||||
foreach (array('dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB') as $prefix) {
|
||||
foreach (['dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB'] as $prefix) {
|
||||
$changed += 1000;
|
||||
$node = $this->drupalCreateNode(array('title' => $prefix . $this->randomMachineName(6)));
|
||||
$node = $this->drupalCreateNode(['title' => $prefix . $this->randomMachineName(6)]);
|
||||
db_update('node_field_data')
|
||||
->fields(array('changed' => $changed))
|
||||
->fields(['changed' => $changed])
|
||||
->condition('nid', $node->id())
|
||||
->execute();
|
||||
}
|
||||
|
||||
// Test that the default sort by node.changed DESC actually fires properly.
|
||||
$nodes_query = db_select('node_field_data', 'n')
|
||||
->fields('n', array('title'))
|
||||
->fields('n', ['title'])
|
||||
->orderBy('changed', 'DESC')
|
||||
->execute()
|
||||
->fetchCol();
|
||||
|
||||
$this->drupalGet('admin/content');
|
||||
foreach ($nodes_query as $delta => $string) {
|
||||
$elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', array(':class' => 'views-table', ':label' => $string));
|
||||
$elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', [':class' => 'views-table', ':label' => $string]);
|
||||
$this->assertTrue(!empty($elements), 'The node was found in the correct order.');
|
||||
}
|
||||
|
||||
// Compare the rendered HTML node list to a query for the nodes ordered by
|
||||
// title to account for possible database-dependent sort order.
|
||||
$nodes_query = db_select('node_field_data', 'n')
|
||||
->fields('n', array('title'))
|
||||
->fields('n', ['title'])
|
||||
->orderBy('title')
|
||||
->execute()
|
||||
->fetchCol();
|
||||
|
||||
$this->drupalGet('admin/content', array('query' => array('sort' => 'asc', 'order' => 'title')));
|
||||
$this->drupalGet('admin/content', ['query' => ['sort' => 'asc', 'order' => 'title']]);
|
||||
foreach ($nodes_query as $delta => $string) {
|
||||
$elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', array(':class' => 'views-table', ':label' => $string));
|
||||
$elements = $this->xpath('//table[contains(@class, :class)]/tbody/tr[' . ($delta + 1) . ']/td[2]/a[normalize-space(text())=:label]', [':class' => 'views-table', ':label' => $string]);
|
||||
$this->assertTrue(!empty($elements), 'The node was found in the correct order.');
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ class NodeAdminTest extends NodeTestBase {
|
|||
*
|
||||
* @see TaxonomyNodeFilterTestCase
|
||||
*/
|
||||
function testContentAdminPages() {
|
||||
public function testContentAdminPages() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Use an explicit changed time to ensure the expected order in the content
|
||||
|
@ -118,10 +118,10 @@ class NodeAdminTest extends NodeTestBase {
|
|||
// they appear in the following code, and the 'content' View has a table
|
||||
// style configuration with a default sort on the 'changed' field DESC.
|
||||
$time = time();
|
||||
$nodes['published_page'] = $this->drupalCreateNode(array('type' => 'page', 'changed' => $time--));
|
||||
$nodes['published_article'] = $this->drupalCreateNode(array('type' => 'article', 'changed' => $time--));
|
||||
$nodes['unpublished_page_1'] = $this->drupalCreateNode(array('type' => 'page', 'changed' => $time--, 'uid' => $this->baseUser1->id(), 'status' => 0));
|
||||
$nodes['unpublished_page_2'] = $this->drupalCreateNode(array('type' => 'page', 'changed' => $time, 'uid' => $this->baseUser2->id(), 'status' => 0));
|
||||
$nodes['published_page'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--]);
|
||||
$nodes['published_article'] = $this->drupalCreateNode(['type' => 'article', 'changed' => $time--]);
|
||||
$nodes['unpublished_page_1'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--, 'uid' => $this->baseUser1->id(), 'status' => 0]);
|
||||
$nodes['unpublished_page_2'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time, 'uid' => $this->baseUser2->id(), 'status' => 0]);
|
||||
|
||||
// Verify view, edit, and delete links for any content.
|
||||
$this->drupalGet('admin/content');
|
||||
|
@ -139,14 +139,14 @@ class NodeAdminTest extends NodeTestBase {
|
|||
}
|
||||
|
||||
// Verify filtering by publishing status.
|
||||
$this->drupalGet('admin/content', array('query' => array('status' => TRUE)));
|
||||
$this->drupalGet('admin/content', ['query' => ['status' => TRUE]]);
|
||||
|
||||
$this->assertLinkByHref('node/' . $nodes['published_page']->id() . '/edit');
|
||||
$this->assertLinkByHref('node/' . $nodes['published_article']->id() . '/edit');
|
||||
$this->assertNoLinkByHref('node/' . $nodes['unpublished_page_1']->id() . '/edit');
|
||||
|
||||
// Verify filtering by status and content type.
|
||||
$this->drupalGet('admin/content', array('query' => array('status' => TRUE, 'type' => 'page')));
|
||||
$this->drupalGet('admin/content', ['query' => ['status' => TRUE, 'type' => 'page']]);
|
||||
|
||||
$this->assertLinkByHref('node/' . $nodes['published_page']->id() . '/edit');
|
||||
$this->assertNoLinkByHref('node/' . $nodes['published_article']->id() . '/edit');
|
||||
|
|
|
@ -35,14 +35,14 @@ class NodeBlockFunctionalTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'views');
|
||||
public static $modules = ['block', 'views'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create users and test node.
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'administer blocks', 'access content overview'));
|
||||
$this->webUser = $this->drupalCreateUser(array('access content', 'create article content'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer content types', 'administer nodes', 'administer blocks', 'access content overview']);
|
||||
$this->webUser = $this->drupalCreateUser(['access content', 'create article content']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,34 +52,34 @@ class NodeBlockFunctionalTest extends NodeTestBase {
|
|||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Disallow anonymous users to view content.
|
||||
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
|
||||
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
|
||||
'access content' => FALSE,
|
||||
));
|
||||
]);
|
||||
|
||||
// Enable the recent content block with two items.
|
||||
$block = $this->drupalPlaceBlock('views_block:content_recent-block_1', array('id' => 'test_block', 'items_per_page' => 2));
|
||||
$block = $this->drupalPlaceBlock('views_block:content_recent-block_1', ['id' => 'test_block', 'items_per_page' => 2]);
|
||||
|
||||
// Test that block is not visible without nodes.
|
||||
$this->drupalGet('');
|
||||
$this->assertText(t('No content available.'), 'Block with "No content available." found.');
|
||||
|
||||
// Add some test nodes.
|
||||
$default_settings = array('uid' => $this->webUser->id(), 'type' => 'article');
|
||||
$default_settings = ['uid' => $this->webUser->id(), 'type' => 'article'];
|
||||
$node1 = $this->drupalCreateNode($default_settings);
|
||||
$node2 = $this->drupalCreateNode($default_settings);
|
||||
$node3 = $this->drupalCreateNode($default_settings);
|
||||
|
||||
// Change the changed time for node so that we can test ordering.
|
||||
db_update('node_field_data')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'changed' => $node1->getChangedTime() + 100,
|
||||
))
|
||||
])
|
||||
->condition('nid', $node2->id())
|
||||
->execute();
|
||||
db_update('node_field_data')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'changed' => $node1->getChangedTime() + 200,
|
||||
))
|
||||
])
|
||||
->condition('nid', $node3->id())
|
||||
->execute();
|
||||
|
||||
|
@ -131,7 +131,7 @@ class NodeBlockFunctionalTest extends NodeTestBase {
|
|||
$this->assertTrue(isset($visibility['node_type']['bundles']['article']), 'Visibility settings were saved to configuration');
|
||||
|
||||
// Create a page node.
|
||||
$node5 = $this->drupalCreateNode(array('uid' => $this->adminUser->id(), 'type' => 'page'));
|
||||
$node5 = $this->drupalCreateNode(['uid' => $this->adminUser->id(), 'type' => 'page']);
|
||||
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->webUser);
|
||||
|
|
|
@ -43,8 +43,8 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->webUser = $this->drupalCreateUser(array('edit own page content', 'create page content'));
|
||||
$this->adminUser = $this->drupalCreateUser(array('bypass node access', 'administer nodes'));
|
||||
$this->webUser = $this->drupalCreateUser(['edit own page content', 'create page content']);
|
||||
$this->adminUser = $this->drupalCreateUser(['bypass node access', 'administer nodes']);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
|
||||
$this->nodeStorage = $this->container->get('entity.manager')->getStorage('node');
|
||||
|
@ -59,7 +59,7 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
$title_key = 'title[0][value]';
|
||||
$body_key = 'body[0][value]';
|
||||
// Create node to edit.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$title_key] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
||||
|
@ -79,7 +79,7 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
|
||||
// Edit the content of the node.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$title_key] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
// Stay on the current page, without reloading.
|
||||
|
@ -90,11 +90,11 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
|
||||
// Log in as a second administrator user.
|
||||
$second_web_user = $this->drupalCreateUser(array('administer nodes', 'edit any page content'));
|
||||
$second_web_user = $this->drupalCreateUser(['administer nodes', 'edit any page content']);
|
||||
$this->drupalLogin($second_web_user);
|
||||
// Edit the same node, creating a new revision.
|
||||
$this->drupalGet("node/" . $node->id() . "/edit");
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$edit['revision'] = TRUE;
|
||||
|
@ -111,6 +111,25 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
$first_node_version = node_revision_load($node->getRevisionId());
|
||||
$second_node_version = node_revision_load($revised_node->getRevisionId());
|
||||
$this->assertNotIdentical($first_node_version->getRevisionUser()->id(), $second_node_version->getRevisionUser()->id(), 'Each revision has a distinct user.');
|
||||
|
||||
// Check if the node revision checkbox is rendered on node edit form.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->assertFieldById('edit-revision', NULL, 'The revision field is present.');
|
||||
|
||||
// Check that details form element opens when there are errors on child
|
||||
// elements.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$edit = [];
|
||||
// This invalid date will trigger an error.
|
||||
$edit['created[0][value][date]'] = $this->randomMachineName(8);
|
||||
// Get the current amount of open details elements.
|
||||
$open_details_elements = count($this->cssSelect('details[open="open"]'));
|
||||
$this->drupalPostForm(NULL, $edit, t('Save and keep published'));
|
||||
// The node author details must be open.
|
||||
$this->assertRaw('<details class="node-form-author js-form-wrapper form-wrapper" data-drupal-selector="edit-author" id="edit-author" open="open">');
|
||||
// Only one extra details element should now be open.
|
||||
$open_details_elements++;
|
||||
$this->assertEqual(count($this->cssSelect('details[open="open"]')), $open_details_elements, 'Exactly one extra open <details> element found.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,7 +140,7 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
|
||||
// Create node to edit.
|
||||
$body_key = 'body[0][value]';
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Save and publish'));
|
||||
|
@ -154,7 +173,7 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
|
||||
// Save the node without making any changes.
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and keep published'));
|
||||
$this->nodeStorage->resetCache(array($node->id()));
|
||||
$this->nodeStorage->resetCache([$node->id()]);
|
||||
$node = $this->nodeStorage->load($node->id());
|
||||
$this->assertIdentical($this->webUser->id(), $node->getOwner()->id());
|
||||
|
||||
|
@ -166,7 +185,7 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
// Check that saving the node without making any changes keeps the proper
|
||||
// author ID.
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and keep published'));
|
||||
$this->nodeStorage->resetCache(array($node->id()));
|
||||
$this->nodeStorage->resetCache([$node->id()]);
|
||||
$node = $this->nodeStorage->load($node->id());
|
||||
$this->assertIdentical($this->webUser->id(), $node->getOwner()->id());
|
||||
}
|
||||
|
@ -181,17 +200,17 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
*/
|
||||
protected function checkVariousAuthoredByValues(NodeInterface $node, $form_element_name) {
|
||||
// Try to change the 'authored by' field to an invalid user name.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$form_element_name => 'invalid-name',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
|
||||
$this->assertRaw(t('There are no entities matching "%name".', array('%name' => 'invalid-name')));
|
||||
$this->assertRaw(t('There are no entities matching "%name".', ['%name' => 'invalid-name']));
|
||||
|
||||
// Change the authored by field to an empty string, which should assign
|
||||
// authorship to the anonymous user (uid 0).
|
||||
$edit[$form_element_name] = '';
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
|
||||
$this->nodeStorage->resetCache(array($node->id()));
|
||||
$this->nodeStorage->resetCache([$node->id()]);
|
||||
$node = $this->nodeStorage->load($node->id());
|
||||
$uid = $node->getOwnerId();
|
||||
// Most SQL database drivers stringify fetches but entities are not
|
||||
|
@ -210,7 +229,7 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
// logged in).
|
||||
$edit[$form_element_name] = $this->webUser->getUsername();
|
||||
$this->drupalPostForm(NULL, $edit, t('Save and keep published'));
|
||||
$this->nodeStorage->resetCache(array($node->id()));
|
||||
$this->nodeStorage->resetCache([$node->id()]);
|
||||
$node = $this->nodeStorage->load($node->id());
|
||||
$this->assertIdentical($node->getOwnerId(), $this->webUser->id(), 'Node authored by normal user.');
|
||||
}
|
||||
|
|
|
@ -14,17 +14,17 @@ class NodeEntityViewModeAlterTest extends NodeTestBase {
|
|||
/**
|
||||
* Enable dummy module that implements hook_ENTITY_TYPE_view() for nodes.
|
||||
*/
|
||||
public static $modules = array('node_test');
|
||||
public static $modules = ['node_test'];
|
||||
|
||||
/**
|
||||
* Create a "Basic page" node and verify its consistency in the database.
|
||||
*/
|
||||
function testNodeViewModeChange() {
|
||||
$web_user = $this->drupalCreateUser(array('create page content', 'edit own page content'));
|
||||
public function testNodeViewModeChange() {
|
||||
$web_user = $this->drupalCreateUser(['create page content', 'edit own page content']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Create a node.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['body[0][value]'] = t('Data that should appear only in the body for the node.');
|
||||
$edit['body[0][summary]'] = t('Extra data that should appear only in the teaser for the node.');
|
||||
|
|
|
@ -20,31 +20,31 @@ class NodeFieldMultilingualTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'language');
|
||||
public static $modules = ['node', 'language'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create Basic page node type.
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Setup users.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'create page content', 'edit own page content'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages', 'create page content', 'edit own page content']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Add a new language.
|
||||
ConfigurableLanguage::createFromLangcode('it')->save();
|
||||
|
||||
// Enable URL language detection and selection.
|
||||
$edit = array('language_interface[enabled][language-url]' => '1');
|
||||
$edit = ['language_interface[enabled][language-url]' => '1'];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
|
||||
// Set "Basic page" content type to use multilingual support.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_configuration[language_alterable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
$this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.');
|
||||
$this->assertRaw(t('The content type %type has been updated.', ['%type' => 'Basic page']), 'Basic page content type has been updated.');
|
||||
|
||||
// Make node body translatable.
|
||||
$field_storage = FieldStorageConfig::loadByName('node', 'body');
|
||||
|
@ -55,7 +55,7 @@ class NodeFieldMultilingualTest extends WebTestBase {
|
|||
/**
|
||||
* Tests whether field languages are correctly set through the node form.
|
||||
*/
|
||||
function testMultilingualNodeForm() {
|
||||
public function testMultilingualNodeForm() {
|
||||
// Create "Basic page" content.
|
||||
$langcode = language_get_default_langcode('node', 'page');
|
||||
$title_key = 'title[0][value]';
|
||||
|
@ -64,7 +64,7 @@ class NodeFieldMultilingualTest extends WebTestBase {
|
|||
$body_value = $this->randomMachineName(16);
|
||||
|
||||
// Create node to edit.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$title_key] = $title_value;
|
||||
$edit[$body_key] = $body_value;
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
||||
|
@ -77,17 +77,17 @@ class NodeFieldMultilingualTest extends WebTestBase {
|
|||
// Change node language.
|
||||
$langcode = 'it';
|
||||
$this->drupalGet("node/{$node->id()}/edit");
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$title_key => $this->randomMachineName(8),
|
||||
'langcode[0][value]' => $langcode,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$node = $this->drupalGetNodeByTitle($edit[$title_key], TRUE);
|
||||
$this->assertTrue($node, 'Node found in database.');
|
||||
$this->assertTrue($node->language()->getId() == $langcode && $node->body->value == $body_value, 'Field language correctly changed.');
|
||||
|
||||
// Enable content language URL detection.
|
||||
$this->container->get('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0));
|
||||
$this->container->get('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, [LanguageNegotiationUrl::METHOD_ID => 0]);
|
||||
|
||||
// Test multilingual field language fallback logic.
|
||||
$this->drupalGet("it/node/{$node->id()}");
|
||||
|
@ -100,7 +100,7 @@ class NodeFieldMultilingualTest extends WebTestBase {
|
|||
/**
|
||||
* Tests multilingual field display settings.
|
||||
*/
|
||||
function testMultilingualDisplaySettings() {
|
||||
public function testMultilingualDisplaySettings() {
|
||||
// Create "Basic page" content.
|
||||
$title_key = 'title[0][value]';
|
||||
$title_value = $this->randomMachineName(8);
|
||||
|
@ -108,7 +108,7 @@ class NodeFieldMultilingualTest extends WebTestBase {
|
|||
$body_value = $this->randomMachineName(16);
|
||||
|
||||
// Create node to edit.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$title_key] = $title_value;
|
||||
$edit[$body_key] = $body_value;
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
||||
|
@ -119,10 +119,10 @@ class NodeFieldMultilingualTest extends WebTestBase {
|
|||
|
||||
// Check if node body is showed.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$body = $this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]//div[contains(concat(" ", normalize-space(@class), " "), :content-class)]/descendant::p', array(
|
||||
$body = $this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]//div[contains(concat(" ", normalize-space(@class), " "), :content-class)]/descendant::p', [
|
||||
':node-class' => ' node ',
|
||||
':content-class' => 'node__content',
|
||||
));
|
||||
]);
|
||||
$this->assertEqual(current($body), $node->body->value, 'Node body found.');
|
||||
}
|
||||
|
||||
|
|
|
@ -29,26 +29,26 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create a user that has no access to change the state of the node.
|
||||
$this->webUser = $this->drupalCreateUser(array('create article content', 'edit own article content'));
|
||||
$this->webUser = $this->drupalCreateUser(['create article content', 'edit own article content']);
|
||||
// Create a user that has access to change the state of the node.
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer nodes', 'bypass node access'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer nodes', 'bypass node access']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the right buttons are displayed for saving nodes.
|
||||
*/
|
||||
function testNodeFormButtons() {
|
||||
public function testNodeFormButtons() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
// Log in as administrative user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Verify the buttons on a node add form.
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertButtons(array(t('Save and publish'), t('Save as unpublished')));
|
||||
$this->assertButtons([t('Save and publish'), t('Save as unpublished')]);
|
||||
|
||||
// Save the node and assert it's published after clicking
|
||||
// 'Save and publish'.
|
||||
$edit = array('title[0][value]' => $this->randomString());
|
||||
$edit = ['title[0][value]' => $this->randomString()];
|
||||
$this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
|
||||
|
||||
// Get the node.
|
||||
|
@ -57,25 +57,25 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
|
||||
// Verify the buttons on a node edit form.
|
||||
$this->drupalGet('node/' . $node_1->id() . '/edit');
|
||||
$this->assertButtons(array(t('Save and keep published'), t('Save and unpublish')));
|
||||
$this->assertButtons([t('Save and keep published'), t('Save and unpublish')]);
|
||||
|
||||
// Save the node and verify it's still published after clicking
|
||||
// 'Save and keep published'.
|
||||
$this->drupalPostForm(NULL, $edit, t('Save and keep published'));
|
||||
$node_storage->resetCache(array(1));
|
||||
$node_storage->resetCache([1]);
|
||||
$node_1 = $node_storage->load(1);
|
||||
$this->assertTrue($node_1->isPublished(), 'Node is published');
|
||||
|
||||
// Save the node and verify it's unpublished after clicking
|
||||
// 'Save and unpublish'.
|
||||
$this->drupalPostForm('node/' . $node_1->id() . '/edit', $edit, t('Save and unpublish'));
|
||||
$node_storage->resetCache(array(1));
|
||||
$node_storage->resetCache([1]);
|
||||
$node_1 = $node_storage->load(1);
|
||||
$this->assertFalse($node_1->isPublished(), 'Node is unpublished');
|
||||
|
||||
// Verify the buttons on an unpublished node edit screen.
|
||||
$this->drupalGet('node/' . $node_1->id() . '/edit');
|
||||
$this->assertButtons(array(t('Save and keep unpublished'), t('Save and publish')));
|
||||
$this->assertButtons([t('Save and keep unpublished'), t('Save and publish')]);
|
||||
|
||||
// Create a node as a normal user.
|
||||
$this->drupalLogout();
|
||||
|
@ -83,10 +83,10 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
|
||||
// Verify the buttons for a normal user.
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertButtons(array(t('Save')), FALSE);
|
||||
$this->assertButtons([t('Save')], FALSE);
|
||||
|
||||
// Create the node.
|
||||
$edit = array('title[0][value]' => $this->randomString());
|
||||
$edit = ['title[0][value]' => $this->randomString()];
|
||||
$this->drupalPostForm('node/add/article', $edit, t('Save'));
|
||||
$node_2 = $node_storage->load(2);
|
||||
$this->assertTrue($node_2->isPublished(), 'Node is published');
|
||||
|
@ -95,8 +95,8 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
// was created by the normal user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalPostForm('node/' . $node_2->id() . '/edit', array(), t('Save and unpublish'));
|
||||
$node_storage->resetCache(array(2));
|
||||
$this->drupalPostForm('node/' . $node_2->id() . '/edit', [], t('Save and unpublish'));
|
||||
$node_storage->resetCache([2]);
|
||||
$node_2 = $node_storage->load(2);
|
||||
$this->assertFalse($node_2->isPublished(), 'Node is unpublished');
|
||||
|
||||
|
@ -104,8 +104,8 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
// it's still unpublished.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->webUser);
|
||||
$this->drupalPostForm('node/' . $node_2->id() . '/edit', array(), t('Save'));
|
||||
$node_storage->resetCache(array(2));
|
||||
$this->drupalPostForm('node/' . $node_2->id() . '/edit', [], t('Save'));
|
||||
$node_storage->resetCache([2]);
|
||||
$node_2 = $node_storage->load(2);
|
||||
$this->assertFalse($node_2->isPublished(), 'Node is still unpublished');
|
||||
$this->drupalLogout();
|
||||
|
@ -121,12 +121,12 @@ class NodeFormButtonsTest extends NodeTestBase {
|
|||
// Verify the buttons on a node add form for an administrator.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertButtons(array(t('Save as unpublished'), t('Save and publish')));
|
||||
$this->assertButtons([t('Save as unpublished'), t('Save and publish')]);
|
||||
|
||||
// Verify the node is unpublished by default for a normal user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->webUser);
|
||||
$edit = array('title[0][value]' => $this->randomString());
|
||||
$edit = ['title[0][value]' => $this->randomString()];
|
||||
$this->drupalPostForm('node/add/article', $edit, t('Save'));
|
||||
$node_3 = $node_storage->load(3);
|
||||
$this->assertFalse($node_3->isPublished(), 'Node is unpublished');
|
||||
|
|
|
@ -14,7 +14,7 @@ class NodeQueryAlterTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node_access_test');
|
||||
public static $modules = ['node_access_test'];
|
||||
|
||||
/**
|
||||
* User with permission to view content.
|
||||
|
@ -39,9 +39,9 @@ class NodeQueryAlterTest extends NodeTestBase {
|
|||
|
||||
// Create user with simple node access permission. The 'node test view'
|
||||
// permission is implemented and granted by the node_access_test module.
|
||||
$this->accessUser = $this->drupalCreateUser(array('access content overview', 'access content', 'node test view'));
|
||||
$this->noAccessUser = $this->drupalCreateUser(array('access content overview', 'access content'));
|
||||
$this->noAccessUser2 = $this->drupalCreateUser(array('access content overview', 'access content'));
|
||||
$this->accessUser = $this->drupalCreateUser(['access content overview', 'access content', 'node test view']);
|
||||
$this->noAccessUser = $this->drupalCreateUser(['access content overview', 'access content']);
|
||||
$this->noAccessUser2 = $this->drupalCreateUser(['access content overview', 'access content']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ class NodeQueryAlterTest extends NodeTestBase {
|
|||
* Verifies that a non-standard table alias can be used, and that a user with
|
||||
* node access can view the nodes.
|
||||
*/
|
||||
function testNodeQueryAlterLowLevelWithAccess() {
|
||||
public function testNodeQueryAlterLowLevelWithAccess() {
|
||||
// User with access should be able to view 4 nodes.
|
||||
try {
|
||||
$query = db_select('node', 'mytab')
|
||||
|
@ -91,7 +91,7 @@ class NodeQueryAlterTest extends NodeTestBase {
|
|||
* Verifies that a non-standard table alias can be used, and that a user
|
||||
* without node access cannot view the nodes.
|
||||
*/
|
||||
function testNodeQueryAlterLowLevelNoAccess() {
|
||||
public function testNodeQueryAlterLowLevelNoAccess() {
|
||||
// User without access should be able to view 0 nodes.
|
||||
try {
|
||||
$query = db_select('node', 'mytab')
|
||||
|
@ -114,7 +114,7 @@ class NodeQueryAlterTest extends NodeTestBase {
|
|||
* Verifies that a non-standard table alias can be used, and that a user with
|
||||
* view-only node access cannot edit the nodes.
|
||||
*/
|
||||
function testNodeQueryAlterLowLevelEditAccess() {
|
||||
public function testNodeQueryAlterLowLevelEditAccess() {
|
||||
// User with view-only access should not be able to edit nodes.
|
||||
try {
|
||||
$query = db_select('node', 'mytab')
|
||||
|
@ -142,15 +142,15 @@ class NodeQueryAlterTest extends NodeTestBase {
|
|||
* add a record to {node_access} paired with a corresponding privilege in
|
||||
* hook_node_grants().
|
||||
*/
|
||||
function testNodeQueryAlterOverride() {
|
||||
$record = array(
|
||||
public function testNodeQueryAlterOverride() {
|
||||
$record = [
|
||||
'nid' => 0,
|
||||
'gid' => 0,
|
||||
'realm' => 'node_access_all',
|
||||
'grant_view' => 1,
|
||||
'grant_update' => 0,
|
||||
'grant_delete' => 0,
|
||||
);
|
||||
];
|
||||
db_insert('node_access')->fields($record)->execute();
|
||||
|
||||
// Test that the noAccessUser still doesn't have the 'view'
|
||||
|
|
|
@ -21,30 +21,30 @@ class NodeRevisionPermissionsTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $accounts = array();
|
||||
protected $accounts = [];
|
||||
|
||||
// Map revision permission names to node revision access ops.
|
||||
protected $map = array(
|
||||
protected $map = [
|
||||
'view' => 'view all revisions',
|
||||
'update' => 'revert all revisions',
|
||||
'delete' => 'delete all revisions',
|
||||
);
|
||||
];
|
||||
|
||||
// Map revision permission names to node type revision access ops.
|
||||
protected $typeMap = array(
|
||||
protected $typeMap = [
|
||||
'view' => 'view page revisions',
|
||||
'update' => 'revert page revisions',
|
||||
'delete' => 'delete page revisions',
|
||||
);
|
||||
];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$types = array('page', 'article');
|
||||
$types = ['page', 'article'];
|
||||
|
||||
foreach ($types as $type) {
|
||||
// Create a node with several revisions.
|
||||
$nodes[$type] = $this->drupalCreateNode(array('type' => $type));
|
||||
$nodes[$type] = $this->drupalCreateNode(['type' => $type]);
|
||||
$this->nodeRevisions[$type][] = $nodes[$type];
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
|
@ -61,24 +61,24 @@ class NodeRevisionPermissionsTest extends NodeTestBase {
|
|||
/**
|
||||
* Tests general revision access permissions.
|
||||
*/
|
||||
function testNodeRevisionAccessAnyType() {
|
||||
public function testNodeRevisionAccessAnyType() {
|
||||
// Create three users, one with each revision permission.
|
||||
foreach ($this->map as $op => $permission) {
|
||||
// Create the user.
|
||||
$account = $this->drupalCreateUser(
|
||||
array(
|
||||
[
|
||||
'access content',
|
||||
'edit any page content',
|
||||
'delete any page content',
|
||||
$permission,
|
||||
)
|
||||
]
|
||||
);
|
||||
$account->op = $op;
|
||||
$this->accounts[] = $account;
|
||||
}
|
||||
|
||||
// Create an admin account (returns TRUE for all revision permissions).
|
||||
$admin_account = $this->drupalCreateUser(array('access content', 'administer nodes'));
|
||||
$admin_account = $this->drupalCreateUser(['access content', 'administer nodes']);
|
||||
$admin_account->is_admin = TRUE;
|
||||
$this->accounts['admin'] = $admin_account;
|
||||
$accounts['admin'] = $admin_account;
|
||||
|
@ -90,17 +90,17 @@ class NodeRevisionPermissionsTest extends NodeTestBase {
|
|||
$accounts[] = $normal_account;
|
||||
$revision = $this->nodeRevisions['page'][1];
|
||||
|
||||
$parameters = array(
|
||||
$parameters = [
|
||||
'op' => array_keys($this->map),
|
||||
'account' => $this->accounts,
|
||||
);
|
||||
];
|
||||
|
||||
$permutations = $this->generatePermutations($parameters);
|
||||
|
||||
$node_revision_access = \Drupal::service('access_check.node.revision');
|
||||
foreach ($permutations as $case) {
|
||||
// Skip this test if there are no revisions for the node.
|
||||
if (!($revision->isDefaultRevision() && (db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid', array(':nid' => $revision->id()))->fetchField() == 1 || $case['op'] == 'update' || $case['op'] == 'delete'))) {
|
||||
if (!($revision->isDefaultRevision() && (db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid', [':nid' => $revision->id()])->fetchField() == 1 || $case['op'] == 'update' || $case['op'] == 'delete'))) {
|
||||
if (!empty($case['account']->is_admin) || $case['account']->hasPermission($this->map[$case['op']])) {
|
||||
$this->assertTrue($node_revision_access->checkAccess($revision, $case['account'], $case['op']), "{$this->map[$case['op']]} granted.");
|
||||
}
|
||||
|
@ -119,26 +119,26 @@ class NodeRevisionPermissionsTest extends NodeTestBase {
|
|||
/**
|
||||
* Tests revision access permissions for a specific content type.
|
||||
*/
|
||||
function testNodeRevisionAccessPerType() {
|
||||
public function testNodeRevisionAccessPerType() {
|
||||
// Create three users, one with each revision permission.
|
||||
foreach ($this->typeMap as $op => $permission) {
|
||||
// Create the user.
|
||||
$account = $this->drupalCreateUser(
|
||||
array(
|
||||
[
|
||||
'access content',
|
||||
'edit any page content',
|
||||
'delete any page content',
|
||||
$permission,
|
||||
)
|
||||
]
|
||||
);
|
||||
$account->op = $op;
|
||||
$accounts[] = $account;
|
||||
}
|
||||
|
||||
$parameters = array(
|
||||
$parameters = [
|
||||
'op' => array_keys($this->typeMap),
|
||||
'account' => $accounts,
|
||||
);
|
||||
];
|
||||
|
||||
// Test that the accounts have access to the corresponding page revision
|
||||
// permissions.
|
||||
|
@ -148,7 +148,7 @@ class NodeRevisionPermissionsTest extends NodeTestBase {
|
|||
$node_revision_access = \Drupal::service('access_check.node.revision');
|
||||
foreach ($permutations as $case) {
|
||||
// Skip this test if there are no revisions for the node.
|
||||
if (!($revision->isDefaultRevision() && (db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid', array(':nid' => $revision->id()))->fetchField() == 1 || $case['op'] == 'update' || $case['op'] == 'delete'))) {
|
||||
if (!($revision->isDefaultRevision() && (db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid', [':nid' => $revision->id()])->fetchField() == 1 || $case['op'] == 'update' || $case['op'] == 'delete'))) {
|
||||
if (!empty($case['account']->is_admin) || $case['account']->hasPermission($this->typeMap[$case['op']], $case['account'])) {
|
||||
$this->assertTrue($node_revision_access->checkAccess($revision, $case['account'], $case['op']), "{$this->typeMap[$case['op']]} granted.");
|
||||
}
|
||||
|
|
|
@ -47,26 +47,26 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
ConfigurableLanguage::createFromLangcode('it')->save();
|
||||
|
||||
$field_storage_definition = array(
|
||||
$field_storage_definition = [
|
||||
'field_name' => 'untranslatable_string_field',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'string',
|
||||
'cardinality' => 1,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
];
|
||||
$field_storage = FieldStorageConfig::create($field_storage_definition);
|
||||
$field_storage->save();
|
||||
|
||||
$field_definition = array(
|
||||
$field_definition = [
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'page',
|
||||
);
|
||||
];
|
||||
$field = FieldConfig::create($field_definition);
|
||||
$field->save();
|
||||
|
||||
// Create and log in user.
|
||||
$web_user = $this->drupalCreateUser(
|
||||
array(
|
||||
[
|
||||
'view page revisions',
|
||||
'revert page revisions',
|
||||
'delete page revisions',
|
||||
|
@ -75,7 +75,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
'access contextual links',
|
||||
'translate any entity',
|
||||
'administer content types',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->drupalLogin($web_user);
|
||||
|
@ -86,8 +86,8 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
$settings['revision'] = 1;
|
||||
$settings['isDefaultRevision'] = TRUE;
|
||||
|
||||
$nodes = array();
|
||||
$logs = array();
|
||||
$nodes = [];
|
||||
$logs = [];
|
||||
|
||||
// Get original node.
|
||||
$nodes[] = clone $node;
|
||||
|
@ -99,10 +99,10 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
|
||||
// Create revision with a random title and body and update variables.
|
||||
$node->title = $this->randomMachineName();
|
||||
$node->body = array(
|
||||
$node->body = [
|
||||
'value' => $this->randomMachineName(32),
|
||||
'format' => filter_default_format(),
|
||||
);
|
||||
];
|
||||
$node->untranslatable_string_field->value = $this->randomString();
|
||||
$node->setNewRevision();
|
||||
|
||||
|
@ -128,7 +128,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
/**
|
||||
* Checks node revision related operations.
|
||||
*/
|
||||
function testRevisions() {
|
||||
public function testRevisions() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$nodes = $this->nodes;
|
||||
$logs = $this->revisionLogs;
|
||||
|
@ -167,11 +167,11 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
|
||||
|
||||
// Confirm that revisions revert properly.
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert", array(), t('Revert'));
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert", [], t('Revert'));
|
||||
$this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.',
|
||||
array('@type' => 'Basic page', '%title' => $nodes[1]->label(),
|
||||
'%revision-date' => format_date($nodes[1]->getRevisionCreationTime()))), 'Revision reverted.');
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
['@type' => 'Basic page', '%title' => $nodes[1]->label(),
|
||||
'%revision-date' => format_date($nodes[1]->getRevisionCreationTime())]), 'Revision reverted.');
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$reverted_node = $node_storage->load($node->id());
|
||||
$this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.');
|
||||
|
||||
|
@ -190,27 +190,27 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
|
||||
|
||||
// Confirm revisions delete properly.
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", array(), t('Delete'));
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete'));
|
||||
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
|
||||
array('%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
|
||||
'@type' => 'Basic page', '%title' => $nodes[1]->label())), 'Revision deleted.');
|
||||
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()))->fetchField() == 0, 'Revision not found.');
|
||||
['%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
|
||||
'@type' => 'Basic page', '%title' => $nodes[1]->label()]), 'Revision deleted.');
|
||||
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Revision not found.');
|
||||
|
||||
// Set the revision timestamp to an older date to make sure that the
|
||||
// confirmation message correctly displays the stored revision date.
|
||||
$old_revision_date = REQUEST_TIME - 86400;
|
||||
db_update('node_revision')
|
||||
->condition('vid', $nodes[2]->getRevisionId())
|
||||
->fields(array(
|
||||
->fields([
|
||||
'revision_timestamp' => $old_revision_date,
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert", array(), t('Revert'));
|
||||
$this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', array(
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert", [], t('Revert'));
|
||||
$this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [
|
||||
'@type' => 'Basic page',
|
||||
'%title' => $nodes[2]->label(),
|
||||
'%revision-date' => format_date($old_revision_date),
|
||||
)));
|
||||
]));
|
||||
|
||||
// Make a new revision and set it to not be default.
|
||||
// This will create a new revision that is not "front facing".
|
||||
|
@ -232,7 +232,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
// Verify that the non-default revision vid is greater than the default
|
||||
// revision vid.
|
||||
$default_revision = db_select('node', 'n')
|
||||
->fields('n', array('vid'))
|
||||
->fields('n', ['vid'])
|
||||
->condition('nid', $node->id())
|
||||
->execute()
|
||||
->fetchCol();
|
||||
|
@ -297,11 +297,11 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
/**
|
||||
* Checks that revisions are correctly saved without log messages.
|
||||
*/
|
||||
function testNodeRevisionWithoutLogMessage() {
|
||||
public function testNodeRevisionWithoutLogMessage() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
// Create a node with an initial log message.
|
||||
$revision_log = $this->randomMachineName(10);
|
||||
$node = $this->drupalCreateNode(array('revision_log' => $revision_log));
|
||||
$node = $this->drupalCreateNode(['revision_log' => $revision_log]);
|
||||
|
||||
// Save over the same revision and explicitly provide an empty log message
|
||||
// (for example, to mimic the case of a node form submitted with no text in
|
||||
|
@ -317,12 +317,12 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
$node->save();
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$this->assertText($new_title, 'New node title appears on the page.');
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$node_revision = $node_storage->load($node->id());
|
||||
$this->assertEqual($node_revision->revision_log->value, $revision_log, 'After an existing node revision is re-saved without a log message, the original log message is preserved.');
|
||||
|
||||
// Create another node with an initial revision log message.
|
||||
$node = $this->drupalCreateNode(array('revision_log' => $revision_log));
|
||||
$node = $this->drupalCreateNode(['revision_log' => $revision_log]);
|
||||
|
||||
// Save a new node revision without providing a log message, and check that
|
||||
// this revision has an empty log message.
|
||||
|
@ -336,7 +336,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
$node->save();
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$this->assertText($new_title, 'New node title appears on the page.');
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$node_revision = $node_storage->load($node->id());
|
||||
$this->assertTrue(empty($node_revision->revision_log->value), 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
* The decoded JSON response body.
|
||||
*/
|
||||
protected function renderContextualLinks(array $ids, $current_path) {
|
||||
$post = array();
|
||||
$post = [];
|
||||
for ($i = 0; $i < count($ids); $i++) {
|
||||
$post['ids[' . $i . ']'] = $ids[$i];
|
||||
}
|
||||
|
|
|
@ -14,13 +14,13 @@ class NodeSyndicateBlockTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
public static $modules = ['block'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a user and log in.
|
||||
$admin_user = $this->drupalCreateUser(array('administer blocks'));
|
||||
$admin_user = $this->drupalCreateUser(['administer blocks']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ class NodeSyndicateBlockTest extends NodeTestBase {
|
|||
*/
|
||||
public function testSyndicateBlock() {
|
||||
// Place the "Syndicate" block and confirm that it is rendered.
|
||||
$this->drupalPlaceBlock('node_syndicate_block', array('id' => 'test_syndicate_block'));
|
||||
$this->drupalPlaceBlock('node_syndicate_block', ['id' => 'test_syndicate_block']);
|
||||
$this->drupalGet('');
|
||||
$this->assertFieldByXPath('//div[@id="block-test-syndicate-block"]/*', NULL, 'Syndicate block found.');
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ use Drupal\simpletest\WebTestBase;
|
|||
|
||||
/**
|
||||
* Sets up page and article content types.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\node\Functional\NodeTestBase instead.
|
||||
*/
|
||||
abstract class NodeTestBase extends WebTestBase {
|
||||
|
||||
|
@ -16,7 +19,7 @@ abstract class NodeTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'datetime');
|
||||
public static $modules = ['node', 'datetime'];
|
||||
|
||||
/**
|
||||
* The node access control handler.
|
||||
|
@ -33,12 +36,12 @@ abstract class NodeTestBase extends WebTestBase {
|
|||
|
||||
// Create Basic page and Article node types.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(array(
|
||||
$this->drupalCreateContentType([
|
||||
'type' => 'page',
|
||||
'name' => 'Basic page',
|
||||
'display_submitted' => FALSE,
|
||||
));
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
]);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
$this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node');
|
||||
}
|
||||
|
@ -56,7 +59,7 @@ abstract class NodeTestBase extends WebTestBase {
|
|||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user account for which to check access.
|
||||
*/
|
||||
function assertNodeAccess(array $ops, NodeInterface $node, AccountInterface $account) {
|
||||
public function assertNodeAccess(array $ops, NodeInterface $node, AccountInterface $account) {
|
||||
foreach ($ops as $op => $result) {
|
||||
$this->assertEqual($result, $this->accessHandler->access($node, $op, $account), $this->nodeAccessAssertMessage($op, $result, $node->language()->getId()));
|
||||
}
|
||||
|
@ -75,10 +78,10 @@ abstract class NodeTestBase extends WebTestBase {
|
|||
* (optional) The language code indicating which translation of the node
|
||||
* to check. If NULL, the untranslated (fallback) access is checked.
|
||||
*/
|
||||
function assertNodeCreateAccess($bundle, $result, AccountInterface $account, $langcode = NULL) {
|
||||
$this->assertEqual($result, $this->accessHandler->createAccess($bundle, $account, array(
|
||||
public function assertNodeCreateAccess($bundle, $result, AccountInterface $account, $langcode = NULL) {
|
||||
$this->assertEqual($result, $this->accessHandler->createAccess($bundle, $account, [
|
||||
'langcode' => $langcode,
|
||||
)), $this->nodeAccessAssertMessage('create', $result, $langcode));
|
||||
]), $this->nodeAccessAssertMessage('create', $result, $langcode));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,14 +99,14 @@ abstract class NodeTestBase extends WebTestBase {
|
|||
* An assert message string which contains information in plain English
|
||||
* about the node access permission test that was performed.
|
||||
*/
|
||||
function nodeAccessAssertMessage($operation, $result, $langcode = NULL) {
|
||||
public function nodeAccessAssertMessage($operation, $result, $langcode = NULL) {
|
||||
return format_string(
|
||||
'Node access returns @result with operation %op, language code %langcode.',
|
||||
array(
|
||||
[
|
||||
'@result' => $result ? 'true' : 'false',
|
||||
'%op' => $operation,
|
||||
'%langcode' => !empty($langcode) ? $langcode : 'empty'
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class NodeTitleTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('comment', 'views', 'block');
|
||||
public static $modules = ['comment', 'views', 'block'];
|
||||
|
||||
/**
|
||||
* A user with permission to bypass access content.
|
||||
|
@ -35,7 +35,7 @@ class NodeTitleTest extends NodeTestBase {
|
|||
parent::setUp();
|
||||
$this->drupalPlaceBlock('system_breadcrumb_block');
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer nodes', 'create article content', 'create page content', 'post comments'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer nodes', 'create article content', 'create page content', 'post comments']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
}
|
||||
|
@ -43,14 +43,14 @@ class NodeTitleTest extends NodeTestBase {
|
|||
/**
|
||||
* Creates one node and tests if the node title has the correct value.
|
||||
*/
|
||||
function testNodeTitle() {
|
||||
public function testNodeTitle() {
|
||||
// Create "Basic page" content with title.
|
||||
// Add the node to the frontpage so we can test if teaser links are
|
||||
// clickable.
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'title' => $this->randomMachineName(8),
|
||||
'promote' => 1,
|
||||
);
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Test <title> tag.
|
||||
|
@ -64,16 +64,16 @@ class NodeTitleTest extends NodeTestBase {
|
|||
$this->assertEqual(current($this->xpath($xpath)), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
|
||||
|
||||
// Test node title in comment preview.
|
||||
$this->assertEqual(current($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', array(':node-class' => ' node--type-' . $node->bundle() . ' '))), $node->label(), 'Node preview title is equal to node title.', 'Node');
|
||||
$this->assertEqual(current($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])), $node->label(), 'Node preview title is equal to node title.', 'Node');
|
||||
|
||||
// Test node title is clickable on teaser list (/node).
|
||||
$this->drupalGet('node');
|
||||
$this->clickLink($node->label());
|
||||
|
||||
// Test edge case where node title is set to 0.
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'title' => 0,
|
||||
);
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
// Test that 0 appears as <title>.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
@ -84,9 +84,9 @@ class NodeTitleTest extends NodeTestBase {
|
|||
|
||||
// Test edge case where node title contains special characters.
|
||||
$edge_case_title = 'article\'s "title".';
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'title' => $edge_case_title,
|
||||
);
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
// Test that the title appears as <title>. The title will be escaped on the
|
||||
// the page.
|
||||
|
|
|
@ -14,20 +14,20 @@ class NodeTitleXSSTest extends NodeTestBase {
|
|||
/**
|
||||
* Tests XSS functionality with a node entity.
|
||||
*/
|
||||
function testNodeTitleXSS() {
|
||||
public function testNodeTitleXSS() {
|
||||
// Prepare a user to do the stuff.
|
||||
$web_user = $this->drupalCreateUser(array('create page content', 'edit any page content'));
|
||||
$web_user = $this->drupalCreateUser(['create page content', 'edit any page content']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
$xss = '<script>alert("xss")</script>';
|
||||
$title = $xss . $this->randomMachineName();
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $title;
|
||||
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Preview'));
|
||||
$this->assertNoRaw($xss, 'Harmful tags are escaped when previewing a node.');
|
||||
|
||||
$settings = array('title' => $title);
|
||||
$settings = ['title' => $title];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
|
|
@ -35,7 +35,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'language', 'content_translation', 'node', 'datetime', 'field_ui', 'help');
|
||||
public static $modules = ['block', 'language', 'content_translation', 'node', 'datetime', 'field_ui', 'help'];
|
||||
|
||||
/**
|
||||
* The profile to install as a basis for testing.
|
||||
|
@ -50,11 +50,11 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Ensure the help message is shown even with prefixed paths.
|
||||
$this->drupalPlaceBlock('help_block', array('region' => 'content'));
|
||||
$this->drupalPlaceBlock('help_block', ['region' => 'content']);
|
||||
|
||||
// Display the language selector.
|
||||
$this->drupalLogin($this->administrator);
|
||||
$edit = array('language_configuration[language_alterable]' => TRUE);
|
||||
$edit = ['language_configuration[language_alterable]' => TRUE];
|
||||
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
|
||||
$this->drupalLogin($this->translator);
|
||||
}
|
||||
|
@ -75,13 +75,13 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
$this->drupalLogin($this->administrator);
|
||||
// Delete all fields.
|
||||
$this->drupalGet('admin/structure/types/manage/article/fields');
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', [], t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', [], t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', [], t('Delete'));
|
||||
|
||||
// Add a node.
|
||||
$default_langcode = $this->langcodes[0];
|
||||
$values[$default_langcode] = array('title' => array(array('value' => $this->randomMachineName())));
|
||||
$values[$default_langcode] = ['title' => [['value' => $this->randomMachineName()]]];
|
||||
$entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
|
||||
$storage = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId);
|
||||
|
@ -91,14 +91,14 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
// Add a content translation.
|
||||
$langcode = 'fr';
|
||||
$language = ConfigurableLanguage::load($langcode);
|
||||
$values[$langcode] = array('title' => array(array('value' => $this->randomMachineName())));
|
||||
$values[$langcode] = ['title' => [['value' => $this->randomMachineName()]]];
|
||||
|
||||
$entity_type_id = $entity->getEntityTypeId();
|
||||
$add_url = Url::fromRoute("entity.$entity_type_id.content_translation_add", [
|
||||
$entity->getEntityTypeId() => $entity->id(),
|
||||
'source' => $default_langcode,
|
||||
'target' => $langcode
|
||||
], array('language' => $language));
|
||||
], ['language' => $language]);
|
||||
$this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), t('Save and unpublish (this translation)'));
|
||||
|
||||
$storage->resetCache([$this->entityId]);
|
||||
|
@ -112,28 +112,28 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTranslatorPermissions() {
|
||||
return array_merge(parent::getTranslatorPermissions(), array('administer nodes', "edit any $this->bundle content"));
|
||||
return array_merge(parent::getTranslatorPermissions(), ['administer nodes', "edit any $this->bundle content"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEditorPermissions() {
|
||||
return array('administer nodes', 'create article content');
|
||||
return ['administer nodes', 'create article content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAdministratorPermissions() {
|
||||
return array_merge(parent::getAdministratorPermissions(), array('access administration pages', 'administer content types', 'administer node fields', 'access content overview', 'bypass node access', 'administer languages', 'administer themes', 'view the administration theme'));
|
||||
return array_merge(parent::getAdministratorPermissions(), ['access administration pages', 'administer content types', 'administer node fields', 'access content overview', 'bypass node access', 'administer languages', 'administer themes', 'view the administration theme']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNewEntityValues($langcode) {
|
||||
return array('title' => array(array('value' => $this->randomMachineName()))) + parent::getNewEntityValues($langcode);
|
||||
return ['title' => [['value' => $this->randomMachineName()]]] + parent::getNewEntityValues($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,18 +158,18 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
$entity = $storage->load($this->entityId);
|
||||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
|
||||
$actions = array(
|
||||
$actions = [
|
||||
t('Save and keep published'),
|
||||
t('Save and unpublish'),
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($actions as $index => $action) {
|
||||
// (Un)publish the node translations and check that the translation
|
||||
// statuses are (un)published accordingly.
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
$options = array('language' => $languages[$langcode]);
|
||||
$options = ['language' => $languages[$langcode]];
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalPostForm($url, array(), $action . $this->getFormSubmitSuffix($entity, $langcode), $options);
|
||||
$this->drupalPostForm($url, [], $action . $this->getFormSubmitSuffix($entity, $langcode), $options);
|
||||
}
|
||||
$storage->resetCache([$this->entityId]);
|
||||
$entity = $storage->load($this->entityId);
|
||||
|
@ -192,25 +192,25 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
$storage->resetCache([$this->entityId]);
|
||||
$entity = $storage->load($this->entityId);
|
||||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
// Post different base field information for each translation.
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
$user = $this->drupalCreateUser();
|
||||
$values[$langcode] = array(
|
||||
$values[$langcode] = [
|
||||
'uid' => $user->id(),
|
||||
'created' => REQUEST_TIME - mt_rand(0, 1000),
|
||||
'sticky' => (bool) mt_rand(0, 1),
|
||||
'promote' => (bool) mt_rand(0, 1),
|
||||
);
|
||||
$edit = array(
|
||||
];
|
||||
$edit = [
|
||||
'uid[0][target_id]' => $user->getUsername(),
|
||||
'created[0][value][date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
|
||||
'created[0][value][time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
|
||||
'sticky[value]' => $values[$langcode]['sticky'],
|
||||
'promote[value]' => $values[$langcode]['promote'],
|
||||
);
|
||||
$options = array('language' => $languages[$langcode]);
|
||||
];
|
||||
$options = ['language' => $languages[$langcode]];
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode), $options);
|
||||
}
|
||||
|
@ -232,11 +232,11 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
*/
|
||||
public function testTranslationLinkTheme() {
|
||||
$this->drupalLogin($this->administrator);
|
||||
$article = $this->drupalCreateNode(array('type' => 'article', 'langcode' => $this->langcodes[0]));
|
||||
$article = $this->drupalCreateNode(['type' => 'article', 'langcode' => $this->langcodes[0]]);
|
||||
|
||||
// Set up Seven as the admin theme and use it for node editing.
|
||||
$this->container->get('theme_handler')->install(array('seven'));
|
||||
$edit = array();
|
||||
$this->container->get('theme_handler')->install(['seven']);
|
||||
$edit = [];
|
||||
$edit['admin_theme'] = 'seven';
|
||||
$edit['use_admin_theme'] = TRUE;
|
||||
$this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
|
||||
|
@ -259,16 +259,16 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
public function testDisabledBundle() {
|
||||
// Create a bundle that does not have translation enabled.
|
||||
$disabledBundle = $this->randomMachineName();
|
||||
$this->drupalCreateContentType(array('type' => $disabledBundle, 'name' => $disabledBundle));
|
||||
$this->drupalCreateContentType(['type' => $disabledBundle, 'name' => $disabledBundle]);
|
||||
|
||||
// Create a node for each bundle.
|
||||
$node = $this->drupalCreateNode(array(
|
||||
$node = $this->drupalCreateNode([
|
||||
'type' => $this->bundle,
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
));
|
||||
]);
|
||||
|
||||
// Make sure that nothing was inserted into the {content_translation} table.
|
||||
$rows = db_query('SELECT nid, count(nid) AS count FROM {node_field_data} WHERE type <> :type GROUP BY nid HAVING count(nid) >= 2', array(':type' => $this->bundle))->fetchAll();
|
||||
$rows = db_query('SELECT nid, count(nid) AS count FROM {node_field_data} WHERE type <> :type GROUP BY nid HAVING count(nid) >= 2', [':type' => $this->bundle])->fetchAll();
|
||||
$this->assertEqual(0, count($rows));
|
||||
|
||||
// Ensure the translation tab is not accessible.
|
||||
|
@ -287,7 +287,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
$node->setPromoted(TRUE);
|
||||
|
||||
// Create translations.
|
||||
foreach (array_diff($this->langcodes, array($default_langcode)) as $langcode) {
|
||||
foreach (array_diff($this->langcodes, [$default_langcode]) as $langcode) {
|
||||
$values[$langcode] = $this->getNewEntityValues($langcode);
|
||||
$translation = $node->addTranslation($langcode, $values[$langcode]);
|
||||
// Publish and promote the translation to frontpage.
|
||||
|
@ -297,7 +297,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
$node->save();
|
||||
|
||||
// Test that the frontpage view displays the correct translations.
|
||||
\Drupal::service('module_installer')->install(array('views'), TRUE);
|
||||
\Drupal::service('module_installer')->install(['views'], TRUE);
|
||||
$this->rebuildContainer();
|
||||
$this->doTestTranslations('node', $values);
|
||||
|
||||
|
@ -316,7 +316,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
// See also assertTaxonomyPage() in NodeAccessBaseTableTest.
|
||||
$node_href = 'node/' . $node->id();
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
$this->drupalGet('node', array('language' => \Drupal::languageManager()->getLanguage($langcode)));
|
||||
$this->drupalGet('node', ['language' => \Drupal::languageManager()->getLanguage($langcode)]);
|
||||
$num_match_found = 0;
|
||||
if ($langcode == 'en') {
|
||||
// Site default language does not have langcode prefix in the URL.
|
||||
|
@ -338,7 +338,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
// language.
|
||||
$comment_form_href = 'node/' . $node->id() . '#comment-form';
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
$this->drupalGet('node', array('language' => \Drupal::languageManager()->getLanguage($langcode)));
|
||||
$this->drupalGet('node', ['language' => \Drupal::languageManager()->getLanguage($langcode)]);
|
||||
$num_match_found = 0;
|
||||
if ($langcode == 'en') {
|
||||
// Site default language does not have langcode prefix in the URL.
|
||||
|
@ -374,8 +374,8 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
protected function doTestTranslations($path, array $values) {
|
||||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
$this->drupalGet($path, array('language' => $languages[$langcode]));
|
||||
$this->assertText($values[$langcode]['title'][0]['value'], format_string('The %langcode node translation is correctly displayed.', array('%langcode' => $langcode)));
|
||||
$this->drupalGet($path, ['language' => $languages[$langcode]]);
|
||||
$this->assertText($values[$langcode]['title'][0]['value'], format_string('The %langcode node translation is correctly displayed.', ['%langcode' => $langcode]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,8 +398,8 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
foreach ($urls as $alternate_langcode => $language_url) {
|
||||
// Retrieve desired link elements from the HTML head.
|
||||
$links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]',
|
||||
array(':href' => $language_url->toString(), ':hreflang' => $alternate_langcode));
|
||||
$this->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', array('%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString())));
|
||||
[':href' => $language_url->toString(), ':hreflang' => $alternate_langcode]);
|
||||
$this->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', ['%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -446,15 +446,15 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
foreach ($this->langcodes as $langcode) {
|
||||
// We only want to test the title for non-english translations.
|
||||
if ($langcode != 'en') {
|
||||
$options = array('language' => $languages[$langcode]);
|
||||
$options = ['language' => $languages[$langcode]];
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
|
||||
$title = t('<em>Edit @type</em> @title [%language translation]', array(
|
||||
$title = t('<em>Edit @type</em> @title [%language translation]', [
|
||||
'@type' => $type_name,
|
||||
'@title' => $entity->getTranslation($langcode)->label(),
|
||||
'%language' => $languages[$langcode]->getName(),
|
||||
));
|
||||
]);
|
||||
$this->assertRaw($title);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class NodeTypeTest extends NodeTestBase {
|
|||
*
|
||||
* Load available node types and validate the returned data.
|
||||
*/
|
||||
function testNodeTypeGetFunctions() {
|
||||
public function testNodeTypeGetFunctions() {
|
||||
$node_types = NodeType::loadMultiple();
|
||||
$node_names = node_type_get_names();
|
||||
|
||||
|
@ -42,7 +42,7 @@ class NodeTypeTest extends NodeTestBase {
|
|||
/**
|
||||
* Tests creating a content type programmatically and via a form.
|
||||
*/
|
||||
function testNodeTypeCreation() {
|
||||
public function testNodeTypeCreation() {
|
||||
// Create a content type programmatically.
|
||||
$type = $this->drupalCreateContentType();
|
||||
|
||||
|
@ -50,14 +50,14 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
|
||||
|
||||
// Log in a test user.
|
||||
$web_user = $this->drupalCreateUser(array('create ' . $type->label() . ' content'));
|
||||
$web_user = $this->drupalCreateUser(['create ' . $type->label() . ' content']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
$this->drupalGet('node/add/' . $type->id());
|
||||
$this->assertResponse(200, 'The new content type can be accessed at node/add.');
|
||||
|
||||
// Create a content type via the user interface.
|
||||
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
|
||||
$web_user = $this->drupalCreateUser(['bypass node access', 'administer content types']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
$this->drupalGet('node/add');
|
||||
|
@ -66,11 +66,11 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$elements = $this->cssSelect('dl.node-type-list dt');
|
||||
$this->assertEqual(3, count($elements));
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => 'foo',
|
||||
'title_label' => 'title for foo',
|
||||
'type' => 'foo',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/add', $edit, t('Save and manage fields'));
|
||||
$type_exists = (bool) NodeType::load('foo');
|
||||
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
|
||||
|
@ -83,8 +83,8 @@ class NodeTypeTest extends NodeTestBase {
|
|||
/**
|
||||
* Tests editing a node type using the UI.
|
||||
*/
|
||||
function testNodeTypeEditing() {
|
||||
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields'));
|
||||
public function testNodeTypeEditing() {
|
||||
$web_user = $this->drupalCreateUser(['bypass node access', 'administer content types', 'administer node fields']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
$field = FieldConfig::loadByName('node', 'page', 'body');
|
||||
|
@ -96,9 +96,9 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$this->assertRaw('Body', 'Body field was found.');
|
||||
|
||||
// Rename the title field.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'title_label' => 'Foo',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
|
||||
$this->drupalGet('node/add/page');
|
||||
|
@ -106,10 +106,10 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$this->assertNoRaw('Title', 'Old title label was not displayed.');
|
||||
|
||||
// Change the name and the description.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => 'Bar',
|
||||
'description' => 'Lorem ipsum.',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
|
||||
$this->drupalGet('node/add');
|
||||
|
@ -131,9 +131,9 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$this->assertEqual($node_bundles['page']['label'], 'NewBar', 'Node type bundle cache is updated');
|
||||
|
||||
// Remove the body field.
|
||||
$this->drupalPostForm('admin/structure/types/manage/page/fields/node.page.body/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/page/fields/node.page.body/delete', [], t('Delete'));
|
||||
// Resave the settings for this type.
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', array(), t('Save content type'));
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', [], t('Save content type'));
|
||||
// Check that the body field doesn't exist.
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertNoRaw('Body', 'Body field was not found.');
|
||||
|
@ -142,23 +142,23 @@ class NodeTypeTest extends NodeTestBase {
|
|||
/**
|
||||
* Tests deleting a content type that still has content.
|
||||
*/
|
||||
function testNodeTypeDeletion() {
|
||||
public function testNodeTypeDeletion() {
|
||||
// Create a content type programmatically.
|
||||
$type = $this->drupalCreateContentType();
|
||||
|
||||
// Log in a test user.
|
||||
$web_user = $this->drupalCreateUser(array(
|
||||
$web_user = $this->drupalCreateUser([
|
||||
'bypass node access',
|
||||
'administer content types',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Add a new node of this type.
|
||||
$node = $this->drupalCreateNode(array('type' => $type->id()));
|
||||
$node = $this->drupalCreateNode(['type' => $type->id()]);
|
||||
// Attempt to delete the content type, which should not be allowed.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $type->label() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', array('%type' => $type->label())),
|
||||
t('%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', ['%type' => $type->label()]),
|
||||
'The content type will not be deleted until all nodes of that type are removed.'
|
||||
);
|
||||
$this->assertNoText(t('This action cannot be undone.'), 'The node type deletion confirmation form is not available.');
|
||||
|
@ -168,13 +168,13 @@ class NodeTypeTest extends NodeTestBase {
|
|||
// Attempt to delete the content type, which should now be allowed.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $type->label() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('Are you sure you want to delete the content type %type?', array('%type' => $type->label())),
|
||||
t('Are you sure you want to delete the content type %type?', ['%type' => $type->label()]),
|
||||
'The content type is available for deletion.'
|
||||
);
|
||||
$this->assertText(t('This action cannot be undone.'), 'The node type deletion confirmation form is available.');
|
||||
|
||||
// Test that a locked node type could not be deleted.
|
||||
$this->container->get('module_installer')->install(array('node_test_config'));
|
||||
$this->container->get('module_installer')->install(['node_test_config']);
|
||||
// Lock the default node type.
|
||||
$locked = \Drupal::state()->get('node.type.locked');
|
||||
$locked['default'] = 'default';
|
||||
|
@ -186,14 +186,14 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$this->assertNoLink(t('Delete'));
|
||||
$this->drupalGet('admin/structure/types/manage/default/delete');
|
||||
$this->assertResponse(403);
|
||||
$this->container->get('module_installer')->uninstall(array('node_test_config'));
|
||||
$this->container->get('module_installer')->uninstall(['node_test_config']);
|
||||
$this->container = \Drupal::getContainer();
|
||||
unset($locked['default']);
|
||||
\Drupal::state()->set('node.type.locked', $locked);
|
||||
$this->drupalGet('admin/structure/types/manage/default');
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertResponse(200);
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertFalse((bool) NodeType::load('default'), 'Node type with machine default deleted.');
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ class NodeTypeTest extends NodeTestBase {
|
|||
*/
|
||||
public function testNodeTypeFieldUiPermissions() {
|
||||
// Create an admin user who can only manage node fields.
|
||||
$admin_user_1 = $this->drupalCreateUser(array('administer content types', 'administer node fields'));
|
||||
$admin_user_1 = $this->drupalCreateUser(['administer content types', 'administer node fields']);
|
||||
$this->drupalLogin($admin_user_1);
|
||||
|
||||
// Test that the user only sees the actions available to him.
|
||||
|
@ -211,7 +211,7 @@ class NodeTypeTest extends NodeTestBase {
|
|||
$this->assertNoLinkByHref('admin/structure/types/manage/article/display');
|
||||
|
||||
// Create another admin user who can manage node fields display.
|
||||
$admin_user_2 = $this->drupalCreateUser(array('administer content types', 'administer node display'));
|
||||
$admin_user_2 = $this->drupalCreateUser(['administer content types', 'administer node display']);
|
||||
$this->drupalLogin($admin_user_2);
|
||||
|
||||
// Test that the user only sees the actions available to him.
|
||||
|
|
|
@ -89,7 +89,7 @@ class NodeViewTest extends NodeTestBase {
|
|||
public function testMultiByteUtf8() {
|
||||
$title = '🐝';
|
||||
$this->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.');
|
||||
$node = $this->drupalCreateNode(array('title' => $title));
|
||||
$node = $this->drupalCreateNode(['title' => $title]);
|
||||
$this->drupalGet($node->urlInfo());
|
||||
$result = $this->xpath('//span[contains(@class, "field--name-title")]');
|
||||
$this->assertEqual((string) $result[0], $title, 'The passed title was returned.');
|
||||
|
|
|
@ -29,7 +29,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'taxonomy', 'comment', 'image', 'file', 'text', 'node_test', 'menu_ui');
|
||||
public static $modules = ['node', 'taxonomy', 'comment', 'image', 'file', 'text', 'node_test', 'menu_ui'];
|
||||
|
||||
/**
|
||||
* The name of the created field.
|
||||
|
@ -42,7 +42,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
parent::setUp();
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
|
||||
$web_user = $this->drupalCreateUser(array('edit own page content', 'create page content', 'administer menu'));
|
||||
$web_user = $this->drupalCreateUser(['edit own page content', 'create page content', 'administer menu']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Add a vocabulary so we can test different view modes.
|
||||
|
@ -89,37 +89,37 @@ class PagePreviewTest extends NodeTestBase {
|
|||
|
||||
// Create a field.
|
||||
$this->fieldName = Unicode::strtolower($this->randomMachineName());
|
||||
$handler_settings = array(
|
||||
'target_bundles' => array(
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
$this->vocabulary->id() => $this->vocabulary->id(),
|
||||
),
|
||||
],
|
||||
'auto_create' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->createEntityReferenceField('node', 'page', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
|
||||
|
||||
entity_get_form_display('node', 'page', 'default')
|
||||
->setComponent($this->fieldName, array(
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => 'entity_reference_autocomplete_tags',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Show on default display and teaser.
|
||||
entity_get_display('node', 'page', 'default')
|
||||
->setComponent($this->fieldName, array(
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => 'entity_reference_label',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
entity_get_display('node', 'page', 'teaser')
|
||||
->setComponent($this->fieldName, array(
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => 'entity_reference_label',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
entity_get_form_display('node', 'page', 'default')
|
||||
->setComponent('field_image', array(
|
||||
->setComponent('field_image', [
|
||||
'type' => 'image_image',
|
||||
'settings' => [],
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
entity_get_display('node', 'page', 'default')
|
||||
|
@ -143,28 +143,28 @@ class PagePreviewTest extends NodeTestBase {
|
|||
])->save();
|
||||
|
||||
entity_get_form_display('node', 'page', 'default')
|
||||
->setComponent('field_test_multi', array(
|
||||
->setComponent('field_test_multi', [
|
||||
'type' => 'text_textfield',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
entity_get_display('node', 'page', 'default')
|
||||
->setComponent('field_test_multi', array(
|
||||
->setComponent('field_test_multi', [
|
||||
'type' => 'string',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the node preview functionality.
|
||||
*/
|
||||
function testPagePreview() {
|
||||
public function testPagePreview() {
|
||||
$title_key = 'title[0][value]';
|
||||
$body_key = 'body[0][value]';
|
||||
$term_key = $this->fieldName . '[target_id]';
|
||||
|
||||
// Fill in node creation form and preview node.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$title_key] = '<em>' . $this->randomMachineName(8) . '</em>';
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$edit[$term_key] = $this->term->getName();
|
||||
|
@ -178,7 +178,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
$this->drupalPostForm(NULL, ['field_image[0][alt]' => 'Picture of llamas'], t('Preview'));
|
||||
|
||||
// Check that the preview is displaying the title, body and term.
|
||||
$this->assertTitle(t('@title | Drupal', array('@title' => $edit[$title_key])), 'Basic page title is preview.');
|
||||
$this->assertTitle(t('@title | Drupal', ['@title' => $edit[$title_key]]), 'Basic page title is preview.');
|
||||
$this->assertEscaped($edit[$title_key], 'Title displayed and escaped.');
|
||||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
$this->assertText($edit[$term_key], 'Term displayed.');
|
||||
|
@ -195,7 +195,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
->removeComponent('body')
|
||||
->save();
|
||||
|
||||
$view_mode_edit = array('view_mode' => 'teaser');
|
||||
$view_mode_edit = ['view_mode' => 'teaser'];
|
||||
$this->drupalPostForm('node/preview/' . $uuid . '/full', $view_mode_edit, t('Switch'));
|
||||
$this->assertRaw('view-mode-teaser', 'View mode teaser class found.');
|
||||
$this->assertNoText($edit[$body_key], 'Body not displayed.');
|
||||
|
@ -207,20 +207,20 @@ class PagePreviewTest extends NodeTestBase {
|
|||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
$this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.');
|
||||
$this->assertFieldByName('field_image[0][alt]', 'Picture of llamas');
|
||||
$this->drupalPostAjaxForm(NULL, array(), array('field_test_multi_add_more' => t('Add another item')), NULL, array(), array(), 'node-page-form');
|
||||
$this->drupalPostAjaxForm(NULL, [], ['field_test_multi_add_more' => t('Add another item')], NULL, [], [], 'node-page-form');
|
||||
$this->assertFieldByName('field_test_multi[0][value]');
|
||||
$this->assertFieldByName('field_test_multi[1][value]');
|
||||
|
||||
// Return to page preview to check everything is as expected.
|
||||
$this->drupalPostForm(NULL, array(), t('Preview'));
|
||||
$this->assertTitle(t('@title | Drupal', array('@title' => $edit[$title_key])), 'Basic page title is preview.');
|
||||
$this->drupalPostForm(NULL, [], t('Preview'));
|
||||
$this->assertTitle(t('@title | Drupal', ['@title' => $edit[$title_key]]), 'Basic page title is preview.');
|
||||
$this->assertEscaped($edit[$title_key], 'Title displayed and escaped.');
|
||||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
$this->assertText($edit[$term_key], 'Term displayed.');
|
||||
$this->assertLink(t('Back to content editing'));
|
||||
|
||||
// Assert the content is kept when reloading the page.
|
||||
$this->drupalGet('node/add/page', array('query' => array('uuid' => $uuid)));
|
||||
$this->drupalGet('node/add/page', ['query' => ['uuid' => $uuid]]);
|
||||
$this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
|
||||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
$this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.');
|
||||
|
@ -240,7 +240,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
|
||||
// Check with two new terms on the edit form, additionally to the existing
|
||||
// one.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$newterm1 = $this->randomMachineName(8);
|
||||
$newterm2 = $this->randomMachineName(8);
|
||||
$edit[$term_key] = $this->term->getName() . ', ' . $newterm1 . ', ' . $newterm2;
|
||||
|
@ -256,7 +256,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
|
||||
// Check with one more new term, keeping old terms, removing the existing
|
||||
// one.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$newterm3 = $this->randomMachineName(8);
|
||||
$edit[$term_key] = $newterm1 . ', ' . $newterm3 . ', ' . $newterm2;
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
|
||||
|
@ -270,9 +270,9 @@ class PagePreviewTest extends NodeTestBase {
|
|||
|
||||
// Check that editing an existing node after it has been previewed and not
|
||||
// saved doesn't remember the previous changes.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$title_key => $this->randomMachineName(8),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
|
||||
$this->assertText($edit[$title_key], 'New title displayed.');
|
||||
$this->clickLink(t('Back to content editing'));
|
||||
|
@ -289,7 +289,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
$node_type->save();
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertNoRaw('edit-submit');
|
||||
$this->drupalPostForm('node/add/page', array($title_key => 'Preview'), t('Preview'));
|
||||
$this->drupalPostForm('node/add/page', [$title_key => 'Preview'], t('Preview'));
|
||||
$this->clickLink(t('Back to content editing'));
|
||||
$this->assertRaw('edit-submit');
|
||||
|
||||
|
@ -348,8 +348,8 @@ class PagePreviewTest extends NodeTestBase {
|
|||
$this->assertText('Basic page ' . $title . ' has been created.');
|
||||
$node = $this->drupalGetNodeByTitle($title);
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->drupalPostAjaxForm(NULL, [], array('field_test_multi_add_more' => t('Add another item')));
|
||||
$this->drupalPostAjaxForm(NULL, [], array('field_test_multi_add_more' => t('Add another item')));
|
||||
$this->drupalPostAjaxForm(NULL, [], ['field_test_multi_add_more' => t('Add another item')]);
|
||||
$this->drupalPostAjaxForm(NULL, [], ['field_test_multi_add_more' => t('Add another item')]);
|
||||
$edit = [
|
||||
'field_test_multi[1][value]' => $example_text_2,
|
||||
'field_test_multi[2][value]' => $example_text_3,
|
||||
|
@ -394,7 +394,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
/**
|
||||
* Checks the node preview functionality, when using revisions.
|
||||
*/
|
||||
function testPagePreviewWithRevisions() {
|
||||
public function testPagePreviewWithRevisions() {
|
||||
$title_key = 'title[0][value]';
|
||||
$body_key = 'body[0][value]';
|
||||
$term_key = $this->fieldName . '[target_id]';
|
||||
|
@ -404,7 +404,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
$node_type->save();
|
||||
|
||||
// Fill in node creation form and preview node.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$title_key] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$edit[$term_key] = $this->term->id();
|
||||
|
@ -412,7 +412,7 @@ class PagePreviewTest extends NodeTestBase {
|
|||
$this->drupalPostForm('node/add/page', $edit, t('Preview'));
|
||||
|
||||
// Check that the preview is displaying the title, body and term.
|
||||
$this->assertTitle(t('@title | Drupal', array('@title' => $edit[$title_key])), 'Basic page title is preview.');
|
||||
$this->assertTitle(t('@title | Drupal', ['@title' => $edit[$title_key]]), 'Basic page title is preview.');
|
||||
$this->assertText($edit[$title_key], 'Title displayed.');
|
||||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
$this->assertText($edit[$term_key], 'Term displayed.');
|
||||
|
@ -450,18 +450,18 @@ class PagePreviewTest extends NodeTestBase {
|
|||
*/
|
||||
public function testSimultaneousPreview() {
|
||||
$title_key = 'title[0][value]';
|
||||
$node = $this->drupalCreateNode(array());
|
||||
$node = $this->drupalCreateNode([]);
|
||||
|
||||
$edit = array($title_key => 'New page title');
|
||||
$edit = [$title_key => 'New page title'];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
|
||||
$this->assertText($edit[$title_key]);
|
||||
|
||||
$user2 = $this->drupalCreateUser(array('edit any page content'));
|
||||
$user2 = $this->drupalCreateUser(['edit any page content']);
|
||||
$this->drupalLogin($user2);
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->assertFieldByName($title_key, $node->label(), 'No title leaked from previous user.');
|
||||
|
||||
$edit2 = array($title_key => 'Another page title');
|
||||
$edit2 = [$title_key => 'Another page title'];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit2, t('Preview'));
|
||||
$this->assertUrl(\Drupal::url('entity.node.preview', ['node_preview' => $node->uuid(), 'view_mode_id' => 'full'], ['absolute' => TRUE]));
|
||||
$this->assertText($edit2[$title_key]);
|
||||
|
|
|
@ -18,10 +18,10 @@ class SummaryLengthTest extends NodeTestBase {
|
|||
$renderer = $this->container->get('renderer');
|
||||
|
||||
// Create a node to view.
|
||||
$settings = array(
|
||||
'body' => array(array('value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero. Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci. Curabitur feugiat egestas nisl sed accumsan.')),
|
||||
$settings = [
|
||||
'body' => [['value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero. Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci. Curabitur feugiat egestas nisl sed accumsan.']],
|
||||
'promote' => 1,
|
||||
);
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
$this->assertTrue(Node::load($node->id()), 'Node created.');
|
||||
|
||||
|
|
41
web/core/modules/node/src/Tests/Update/NodeUpdateTest.php
Normal file
41
web/core/modules/node/src/Tests/Update/NodeUpdateTest.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\node\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests that node settings are properly updated during database updates.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the node entity type has a 'published' entity key.
|
||||
*
|
||||
* @see node_update_8301()
|
||||
*/
|
||||
public function testPublishedEntityKey() {
|
||||
// Check that the 'published' entity key does not exist prior to the update.
|
||||
$entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('node');
|
||||
$this->assertFalse($entity_type->getKey('published'));
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Check that the entity key exists and it has the correct value.
|
||||
$entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('node');
|
||||
$this->assertEqual('status', $entity_type->getKey('published'));
|
||||
}
|
||||
|
||||
}
|
|
@ -22,14 +22,14 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node_test_views', 'node_access_test');
|
||||
public static $modules = ['node_test_views', 'node_access_test'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_node_bulk_form');
|
||||
public static $testViews = ['test_node_bulk_form'];
|
||||
|
||||
/**
|
||||
* The node access control handler.
|
||||
|
@ -45,7 +45,7 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create Article node type.
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
$this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node');
|
||||
|
||||
|
@ -65,15 +65,15 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
// Create an account who will be the author of a private node.
|
||||
$author = $this->drupalCreateUser();
|
||||
// Create a private node (author may view, edit and delete, others may not).
|
||||
$node = $this->drupalCreateNode(array(
|
||||
$node = $this->drupalCreateNode([
|
||||
'type' => 'article',
|
||||
'private' => array(array(
|
||||
'private' => [[
|
||||
'value' => TRUE,
|
||||
)),
|
||||
]],
|
||||
'uid' => $author->id(),
|
||||
));
|
||||
]);
|
||||
// Create an account that may view the private node, but not edit it.
|
||||
$account = $this->drupalCreateUser(array('node test view'));
|
||||
$account = $this->drupalCreateUser(['node test view']);
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// Ensure the node is published.
|
||||
|
@ -83,10 +83,10 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
$this->assertEqual(FALSE, $this->accessHandler->access($node, 'update', $account), 'The node may not be edited.');
|
||||
|
||||
// Test editing the node using the bulk form.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_unpublish_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-node-bulk-form', $edit, t('Apply to selected items'));
|
||||
$this->assertRaw(SafeMarkup::format('No access to execute %action on the @entity_type_label %entity_label.', [
|
||||
'%action' => 'Unpublish content',
|
||||
|
@ -100,7 +100,7 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
|
||||
// Create an account that may view the private node, but can update the
|
||||
// status.
|
||||
$account = $this->drupalCreateUser(array('administer nodes', 'node test view'));
|
||||
$account = $this->drupalCreateUser(['administer nodes', 'node test view']);
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// Ensure the node is published.
|
||||
|
@ -111,10 +111,10 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
$this->assertEqual(TRUE, $node->status->access('edit', $account), 'The node status can be edited.');
|
||||
|
||||
// Test editing the node using the bulk form.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_unpublish_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-node-bulk-form', $edit, t('Apply to selected items'));
|
||||
// Test that the action message isn't shown.
|
||||
$this->assertNoRaw(SafeMarkup::format('%action was applied to 1 item.', [
|
||||
|
@ -132,25 +132,25 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
// Create an account who will be the author of a private node.
|
||||
$author = $this->drupalCreateUser();
|
||||
// Create a private node (author may view, edit and delete, others may not).
|
||||
$private_node = $this->drupalCreateNode(array(
|
||||
$private_node = $this->drupalCreateNode([
|
||||
'type' => 'article',
|
||||
'private' => array(array(
|
||||
'private' => [[
|
||||
'value' => TRUE,
|
||||
)),
|
||||
]],
|
||||
'uid' => $author->id(),
|
||||
));
|
||||
]);
|
||||
// Create an account that may view the private node, but not delete it.
|
||||
$account = $this->drupalCreateUser(array('access content', 'administer nodes', 'delete own article content', 'node test view'));
|
||||
$account = $this->drupalCreateUser(['access content', 'administer nodes', 'delete own article content', 'node test view']);
|
||||
// Create a node that may be deleted too, to ensure the delete confirmation
|
||||
// page is shown later. In node_access_test.module, nodes may only be
|
||||
// deleted by the author.
|
||||
$own_node = $this->drupalCreateNode(array(
|
||||
$own_node = $this->drupalCreateNode([
|
||||
'type' => 'article',
|
||||
'private' => array(array(
|
||||
'private' => [[
|
||||
'value' => TRUE,
|
||||
)),
|
||||
]],
|
||||
'uid' => $account->id(),
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// Ensure that the private node can not be deleted.
|
||||
|
@ -159,13 +159,13 @@ class BulkFormAccessTest extends NodeTestBase {
|
|||
$this->assertEqual(TRUE, $this->accessHandler->access($own_node, 'delete', $account), 'The own node may be deleted.');
|
||||
|
||||
// Try to delete the node using the bulk form.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'node_bulk_form[1]' => TRUE,
|
||||
'action' => 'node_delete_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-node-bulk-form', $edit, t('Apply to selected items'));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
// Ensure the private node still exists.
|
||||
$private_node = Node::load($private_node->id());
|
||||
$this->assertNotNull($private_node, 'The private node has not been deleted.');
|
||||
|
|
|
@ -19,14 +19,14 @@ class BulkFormTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node_test_views', 'language');
|
||||
public static $modules = ['node_test_views', 'language'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_node_bulk_form');
|
||||
public static $testViews = ['test_node_bulk_form'];
|
||||
|
||||
/**
|
||||
* The test nodes.
|
||||
|
@ -86,7 +86,7 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertEqual(count($view->result), 10, 'All created translations are selected.');
|
||||
|
||||
// Check the operations are accessible to the logged in user.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer nodes', 'access content overview', 'bypass node access')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer nodes', 'access content overview', 'bypass node access']));
|
||||
$this->drupalGet('test-node-bulk-form');
|
||||
$elements = $this->xpath('//select[@id="edit-action"]//option');
|
||||
$this->assertIdentical(count($elements), 8, 'All node operations are found.');
|
||||
|
@ -101,10 +101,10 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertTrue($node->isPublished(), 'Node is initially published');
|
||||
$this->assertTrue($node->getTranslation('en-gb')->isPublished(), 'Node translation is published');
|
||||
$this->assertTrue($node->getTranslation('it')->isPublished(), 'Node translation is published');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_unpublish_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$node = $this->loadNode($node->id());
|
||||
$this->assertFalse($node->isPublished(), 'Node has been unpublished');
|
||||
|
@ -112,10 +112,10 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertTrue($node->getTranslation('it')->isPublished(), 'Node translation has not been unpublished');
|
||||
|
||||
// Publish action.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_publish_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$node = $this->loadNode($node->id());
|
||||
$this->assertTrue($node->isPublished(), 'Node has been published again');
|
||||
|
@ -124,10 +124,10 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertFalse($node->isSticky(), 'Node is not sticky');
|
||||
$this->assertFalse($node->getTranslation('en-gb')->isSticky(), 'Node translation is not sticky');
|
||||
$this->assertFalse($node->getTranslation('it')->isSticky(), 'Node translation is not sticky');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_make_sticky_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$node = $this->loadNode($node->id());
|
||||
$this->assertTrue($node->isSticky(), 'Node has been made sticky');
|
||||
|
@ -135,10 +135,10 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertFalse($node->getTranslation('it')->isSticky(), 'Node translation has not been made sticky');
|
||||
|
||||
// Make unsticky action.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_make_unsticky_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$node = $this->loadNode($node->id());
|
||||
$this->assertFalse($node->isSticky(), 'Node is not sticky anymore');
|
||||
|
@ -147,10 +147,10 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertFalse($node->isPromoted(), 'Node is not promoted to the front page');
|
||||
$this->assertFalse($node->getTranslation('en-gb')->isPromoted(), 'Node translation is not promoted to the front page');
|
||||
$this->assertFalse($node->getTranslation('it')->isPromoted(), 'Node translation is not promoted to the front page');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_promote_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$node = $this->loadNode($node->id());
|
||||
$this->assertTrue($node->isPromoted(), 'Node has been promoted to the front page');
|
||||
|
@ -158,17 +158,17 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertFalse($node->getTranslation('it')->isPromoted(), 'Node translation has not been promoted to the front page');
|
||||
|
||||
// Demote from front page.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'node_bulk_form[0]' => TRUE,
|
||||
'action' => 'node_unpromote_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$node = $this->loadNode($node->id());
|
||||
$this->assertFalse($node->isPromoted(), 'Node has been demoted');
|
||||
|
||||
// Select a bunch of translated and untranslated nodes and check that
|
||||
// operations are always applied to individual translations.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
// Original and all translations.
|
||||
'node_bulk_form[0]' => TRUE, // Node 1, English, original.
|
||||
'node_bulk_form[1]' => TRUE, // Node 1, British English.
|
||||
|
@ -184,7 +184,7 @@ class BulkFormTest extends NodeTestBase {
|
|||
'node_bulk_form[8]' => TRUE, // Node 4, English, untranslated.
|
||||
'node_bulk_form[9]' => FALSE, // Node 5, British English, untranslated.
|
||||
'action' => 'node_unpublish_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$node = $this->loadNode(1);
|
||||
$this->assertFalse($node->getTranslation('en')->isPublished(), '1: English translation has been unpublished');
|
||||
|
@ -209,7 +209,7 @@ class BulkFormTest extends NodeTestBase {
|
|||
public function testBulkDeletion() {
|
||||
// Select a bunch of translated and untranslated nodes and check that
|
||||
// nodes and individual translations are properly deleted.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
// Original and all translations.
|
||||
'node_bulk_form[0]' => TRUE, // Node 1, English, original.
|
||||
'node_bulk_form[1]' => TRUE, // Node 1, British English.
|
||||
|
@ -225,7 +225,7 @@ class BulkFormTest extends NodeTestBase {
|
|||
'node_bulk_form[8]' => TRUE, // Node 4, English, untranslated.
|
||||
'node_bulk_form[9]' => FALSE, // Node 5, British English, untranslated.
|
||||
'action' => 'node_delete_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
|
||||
$label = $this->loadNode(1)->label();
|
||||
|
@ -239,7 +239,7 @@ class BulkFormTest extends NodeTestBase {
|
|||
$this->assertText($label);
|
||||
$this->assertNoText("$label (Original translation) - The following content translations will be deleted:");
|
||||
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
|
||||
$node = $this->loadNode(1);
|
||||
$this->assertNull($node, '1: Node has been deleted');
|
||||
|
|
|
@ -16,7 +16,7 @@ class FilterUidRevisionTest extends NodeTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_filter_node_uid_revision');
|
||||
public static $testViews = ['test_filter_node_uid_revision'];
|
||||
|
||||
/**
|
||||
* Tests the node_uid_revision filter.
|
||||
|
@ -25,14 +25,14 @@ class FilterUidRevisionTest extends NodeTestBase {
|
|||
$author = $this->drupalCreateUser();
|
||||
$no_author = $this->drupalCreateUser();
|
||||
|
||||
$expected_result = array();
|
||||
$expected_result = [];
|
||||
// Create one node, with the author as the node author.
|
||||
$node = $this->drupalCreateNode(array('uid' => $author->id()));
|
||||
$expected_result[] = array('nid' => $node->id());
|
||||
$node = $this->drupalCreateNode(['uid' => $author->id()]);
|
||||
$expected_result[] = ['nid' => $node->id()];
|
||||
// Create one node of which an additional revision author will be the
|
||||
// author.
|
||||
$node = $this->drupalCreateNode(array('revision_uid' => $no_author->id()));
|
||||
$expected_result[] = array('nid' => $node->id());
|
||||
$node = $this->drupalCreateNode(['revision_uid' => $no_author->id()]);
|
||||
$expected_result[] = ['nid' => $node->id()];
|
||||
$revision = clone $node;
|
||||
// Force to add a new revision.
|
||||
$revision->set('vid', NULL);
|
||||
|
@ -41,14 +41,14 @@ class FilterUidRevisionTest extends NodeTestBase {
|
|||
|
||||
// Create one node on which the author has neither authorship of revisions
|
||||
// or the main node.
|
||||
$this->drupalCreateNode(array('uid' => $no_author->id()));
|
||||
$this->drupalCreateNode(['uid' => $no_author->id()]);
|
||||
|
||||
$view = Views::getView('test_filter_node_uid_revision');
|
||||
$view->initHandlers();
|
||||
$view->filter['uid_revision']->value = array($author->id());
|
||||
$view->filter['uid_revision']->value = [$author->id()];
|
||||
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, $expected_result, array('nid' => 'nid'), 'Make sure that the view only returns nodes which match either the node or the revision author.');
|
||||
$this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid'], 'Make sure that the view only returns nodes which match either the node or the revision author.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue