Commit 7d31cc86 authored by alexpott's avatar alexpott

Issue #1548204 by andypost, sun, typhonius, amateescu: Remove user signature and move it to contrib

parent 0880f31c
......@@ -46,6 +46,7 @@ Drupal 8.0, xxxx-xx-xx (development version)
- Removed the Garland theme from core.
- Removed the Statistics module's accesslog functionality and reports from core.
- Removed XML-RPC functionality from core.
- Removed user signatures support from core.
- Removed backwards-compatibility with 'magic_quotes_gpc'/'magic_quotes_runtime'
PHP configuration settings. Both are required to be disabled.
- Universally Unique IDentifier (UUID):
......
......@@ -699,13 +699,6 @@ function template_preprocess_comment(&$variables) {
$variables['user_picture'] = array();
}
if (isset($variables['elements']['signature'])) {
$variables['signature'] = $variables['elements']['signature'];
unset($variables['elements']['signature']);
}
else {
$variables['signature'] = '';
}
if (isset($comment->in_preview)) {
$variables['title'] = \Drupal::l($comment->getSubject(), new Url('<front>'));
$variables['permalink'] = \Drupal::l(t('Permalink'), new Url('<front>'));
......
......@@ -102,18 +102,6 @@ public function buildComponents(array &$build, array $entities, array $displays,
);
}
$account = comment_prepare_author($entity);
$config = \Drupal::config('user.settings');
$build['#cache']['tags'] = Cache::mergeTags(isset($build['#cache']['tags']) ? $build['#cache']['tags'] : [], $config->getCacheTags());
if ($config->get('signatures') && $account->getSignature()) {
$build[$id]['signature'] = array(
'#type' => 'processed_text',
'#text' => $account->getSignature(),
'#format' => $account->getSignatureFormat(),
'#langcode' => $entity->language()->getId(),
);
}
if (!isset($build[$id]['#attached'])) {
$build[$id]['#attached'] = array();
}
......
......@@ -110,7 +110,6 @@ public function testCacheTags() {
'comment_view',
'comment:' . $comment->id(),
'config:filter.format.plain_text',
'config:user.settings',
'user_view',
'user:2',
);
......
......@@ -39,11 +39,8 @@ function testCommentPreview() {
$this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
$this->drupalLogout();
// Login as web user and add a signature and a user picture.
// Login as web user and add a user picture.
$this->drupalLogin($this->webUser);
$this->config('user.settings')->set('signatures', 1)->save();
$test_signature = $this->randomMachineName();
$edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature. '</a>';
$image = current($this->drupalGetTestFiles('image'));
$edit['files[user_picture_0]'] = drupal_realpath($image->uri);
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
......@@ -63,9 +60,6 @@ function testCommentPreview() {
$this->assertFieldByName('subject[0][value]', $edit['subject[0][value]'], 'Subject field displayed.');
$this->assertFieldByName('comment_body[0][value]', $edit['comment_body[0][value]'], 'Comment field displayed.');
// Check that the signature is displaying with the correct text format.
$this->assertLink($test_signature);
// Check that the user picture is displayed.
$this->assertFieldByXPath("//article[contains(@class, 'preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
}
......
......@@ -22,7 +22,6 @@
* - submitted: Submission information created from author and created
* during template_preprocess_comment().
* - user_picture: The comment author's profile picture.
* - signature: The comment author's signature.
* - status: Comment status. Possible values are:
* unpublished, published, or preview.
* - title: Comment title, linked to the comment.
......@@ -103,12 +102,6 @@
<div{{ content_attributes }}>
{{ content|without('links') }}
{% if signature %}
<div>
{{ signature }}
</div>
{% endif %}
</div>
{% if content.links %}
{{ content.links }}
......
......@@ -22,22 +22,6 @@ process:
plugin: migration
migration: d6_user_role
source: roles
signature: signature
signature_format:
-
# Drupal 6 stores 0 as the signature format when signatures are disabled.
# Drupal 8 stores a NULL.
plugin: static_map
bypass: true
source: signature_format
map:
0: NULL
-
# Do not try to migrate the NULL format.
plugin: skip_process_on_empty
-
plugin: migration
migration: d6_filter_format
user_picture:
plugin: d6_user_picture
source: uid
......@@ -46,7 +30,6 @@ destination:
md5_passwords: true
migration_dependencies:
required:
- d6_filter_format
- d6_user_role
optional:
- d6_user_picture_file
......
......@@ -7,14 +7,12 @@ source:
variables:
- user_mail_status_blocked_notify
- user_mail_status_activated_notify
- user_signatures
- user_email_verification
- user_register
- anonymous
process:
'notify/status_blocked': user_mail_status_blocked_notify
'notify/status_activated': user_mail_status_activated_notify
signatures: user_signatures
verify_mail: user_email_verification
register:
plugin: static_map
......
......@@ -134,8 +134,9 @@ protected function processTextField($field_name, $field_data, MigrationInterface
$migration->setProcessOfProperty("$field_name/value", $value_key);
// See d6_user, signature_format for an example of the YAML that
// represents this process array.
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
// signature_format for an example of the YAML that represents this
// process array.
$process = [
[
'plugin' => 'static_map',
......
......@@ -67,7 +67,6 @@ public function testUserSettings() {
$config = $this->config('user.settings');
$this->assertIdentical(TRUE, $config->get('notify.status_blocked'));
$this->assertIdentical(FALSE, $config->get('notify.status_activated'));
$this->assertIdentical(TRUE, $config->get('signatures'));
$this->assertIdentical(FALSE, $config->get('verify_mail'));
$this->assertIdentical('admin_only', $config->get('register'));
$this->assertIdentical('Guest', $config->get('anonymous'));
......
......@@ -100,11 +100,6 @@ protected function setUp() {
$this->loadDumps($dumps);
$id_mappings = array(
'd6_filter_format' => array(
array(array(1), array('filtered_html')),
array(array(2), array('full_html')),
array(array(3), array('escape_html_filter')),
),
'd6_user_role' => array(
array(array(1), array('anonymous user')),
array(array(2), array('authenticated user')),
......@@ -156,16 +151,11 @@ public function testUser() {
$role = $migration_role->getIdMap()->lookupDestinationId(array($rid));
$roles[] = reset($role);
}
// Get the user signature format.
$migration_format = entity_load('migration', 'd6_filter_format');
$signature_format = $source->signature_format === '0' ? [NULL] : $migration_format->getIdMap()->lookupDestinationId(array($source->signature_format));
$user = User::load($source->uid);
$this->assertIdentical($source->uid, $user->id());
$this->assertIdentical($source->name, $user->label());
$this->assertIdentical($source->mail, $user->getEmail());
$this->assertIdentical($source->signature, $user->getSignature());
$this->assertIdentical(reset($signature_format), $user->getSignatureFormat());
$this->assertIdentical($source->created, $user->getCreatedTime());
$this->assertIdentical($source->access, $user->getLastAccessedTime());
$this->assertIdentical($source->login, $user->getLastLoginTime());
......
......@@ -10,7 +10,6 @@ notify:
register_no_approval_required: true
register_pending_approval: true
register: visitors
signatures: false
cancel_method: user_cancel_block
password_reset_timeout: 86400
password_strength: true
......
......@@ -41,9 +41,6 @@ user.settings:
register:
type: string
label: 'Who can register accounts?'
signatures:
type: boolean
label: 'Enable signatures'
cancel_method:
type: string
label: 'When cancelling a user account'
......
......@@ -232,29 +232,6 @@ public function form(array $form, FormStateInterface $form_state) {
'#access' => $register && $admin,
);
// Signature.
$form['signature_settings'] = array(
'#type' => 'details',
'#title' => $this->t('Signature settings'),
'#open' => TRUE,
'#weight' => 1,
'#access' => (!$register && $config->get('signatures')),
);
// While the details group will simply not be rendered if empty, the actual
// signature element cannot use #access, since #type 'text_format' is not
// available when Filter module is not installed. If the user account has an
// existing signature value and format, then the existing field values will
// just be re-saved to the database in case of an entity update.
if ($this->moduleHandler->moduleExists('filter')) {
$form['signature_settings']['signature'] = array(
'#type' => 'text_format',
'#title' => $this->t('Signature'),
'#default_value' => $account->getSignature(),
'#description' => $this->t('Your signature will be publicly displayed at the end of your comments.'),
'#format' => $account->getSignatureFormat(),
);
}
$user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode();
$user_preferred_admin_langcode = $register ? $language_interface->getId() : $account->getPreferredAdminLangcode(FALSE);
......@@ -365,12 +342,6 @@ public function buildEntity(array $form, FormStateInterface $form_state) {
/** @var \Drupal\user\UserInterface $account */
$account = parent::buildEntity($form, $form_state);
// Take care of mapping signature form element values as their structure
// does not directly match the field structure.
$signature = $form_state->getValue('signature');
$account->setSignature($signature['value']);
$account->setSignatureFormat($signature['format']);
// Translate the empty value '' of language selects to an unset field.
foreach (array('preferred_langcode', 'preferred_admin_langcode') as $field_name) {
if ($form_state->getValue($field_name) === '') {
......@@ -393,8 +364,6 @@ public function validate(array $form, FormStateInterface $form_state) {
$field_names = array(
'name',
'mail',
'signature',
'signature_format',
'timezone',
'langcode',
'preferred_langcode',
......
......@@ -194,12 +194,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#open' => TRUE,
'#access' => $filter_exists,
);
$form['personalization']['user_signatures'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Enable signatures'),
'#default_value' => $filter_exists ? $config->get('signatures') : 0,
'#access' => $filter_exists,
);
// Default notifications address.
$form['mail_notification_address'] = array(
......@@ -450,7 +444,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
->set('register', $form_state->getValue('user_register'))
->set('password_strength', $form_state->getValue('user_password_strength'))
->set('verify_mail', $form_state->getValue('user_email_verification'))
->set('signatures', $form_state->getValue('user_signatures'))
->set('cancel_method', $form_state->getValue('user_cancel_method'))
->set('notify.status_activated', $form_state->getValue('user_mail_status_activated_notify'))
->set('notify.status_blocked', $form_state->getValue('user_mail_status_blocked_notify'))
......@@ -493,9 +486,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->roleStorage->load($new_admin_role)->setIsAdmin(TRUE)->save();
}
}
// Clear field definition cache for signatures.
\Drupal::entityManager()->clearCachedFieldDefinitions();
}
}
......@@ -283,36 +283,6 @@ public function setEmail($mail) {
return $this;
}
/**
* {@inheritdoc}
*/
public function getSignature() {
return $this->get('signature')->value;
}
/**
* {@inheritdoc}
*/
public function setSignature($signature) {
$this->get('signature')->value = $signature;
return $this;
}
/**
* {@inheritdoc}
*/
public function getSignatureFormat() {
return $this->get('signature_format')->value;
}
/**
* {@inheritdoc}
*/
public function setSignatureFormat($signature_format) {
$this->get('signature_format')->value = $signature_format;
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -525,20 +495,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->addConstraint('UserMailUnique')
->addConstraint('UserMailRequired');
// @todo Convert to a text field in https://drupal.org/node/1548204.
$fields['signature'] = BaseFieldDefinition::create('string')
->setLabel(t('Signature'))
->setDescription(t('The signature of this user.'))
->setTranslatable(TRUE);
$fields['signature_format'] = BaseFieldDefinition::create('string')
->setLabel(t('Signature format'))
->setDescription(t('The signature format of this user.'))
// @todo: Define this via an options provider once
// https://www.drupal.org/node/2329937 is completed.
->addPropertyConstraints('value', array(
'AllowedValues' => array('callback' => __CLASS__ . '::getAllowedSignatureFormats'),
));
$fields['timezone'] = BaseFieldDefinition::create('string')
->setLabel(t('Timezone'))
->setDescription(t('The timezone of this user.'))
......@@ -596,20 +552,6 @@ protected function getRoleStorage() {
return \Drupal::entityManager()->getStorage('user_role');
}
/**
* Defines allowed signature formats for the field's AllowedValues constraint.
*
* @return string[]
* The allowed values.
*/
public static function getAllowedSignatureFormats() {
if (\Drupal::moduleHandler()->moduleExists('filter')) {
return array_keys(filter_formats());
}
// If filter.module is disabled, no value may be assigned.
return array();
}
/**
* Defines allowed timezones for the field's AllowedValues constraint.
*
......
......@@ -16,51 +16,12 @@
*/
class UserEditTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('filter');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->config('user.settings')->set('signatures', TRUE)->save();
// Prefetch and create text formats.
$this->filtered_html_format = entity_create('filter_format', array(
'format' => 'filtered_html_format',
'name' => 'Filtered HTML',
'weight' => -1,
'filters' => array(
'filter_html' => array(
'module' => 'filter',
'status' => TRUE,
'settings' => array(
'allowed_html' => '<a> <em> <strong>',
),
),
),
));
$this->filtered_html_format->save();
$this->full_html_format = entity_create('filter_format', array(
'format' => 'full_html',
'name' => 'Full HTML',
));
$this->full_html_format->save();
}
/**
* Test user edit page.
*/
function testUserEdit() {
// Test user edit functionality.
$user1 = $this->drupalCreateUser(array('change own username', $this->full_html_format->getPermissionName(), $this->filtered_html_format->getPermissionName()));
$user1 = $this->drupalCreateUser(array('change own username'));
$user2 = $this->drupalCreateUser(array());
$this->drupalLogin($user1);
......@@ -124,11 +85,6 @@ function testUserEdit() {
$config->set('password_strength', FALSE)->save();
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
$this->assertNoRaw(t('Password strength:'), 'The password strength indicator is not displayed.');
// Test user signature
$edit = array('signature[format]' => $this->full_html_format->id(), 'signature[value]' => $this->randomString(256));
$this->drupalPostForm('user/' . $user1->id() . '/edit', $edit, t('Save'));
$this->assertRaw(t("%name: may not be longer than @max characters.", array('%name' => t('Signature'), '@max' => 255)));
}
/**
......
......@@ -184,7 +184,6 @@ function testRegistrationDefaultValues() {
$new_user = reset($accounts);
$this->assertEqual($new_user->getUsername(), $name, 'Username matches.');
$this->assertEqual($new_user->getEmail(), $mail, 'Email address matches.');
$this->assertEqual($new_user->getSignature(), '', 'Correct signature field.');
$this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20 ), 'Correct creation time.');
$this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
$this->assertEqual($new_user->getTimezone(), $config_system_date->get('timezone.default'), 'Correct time zone field.');
......
<?php
/**
* @file
* Definition of Drupal\user\Tests\UserSignatureTest.
*/
namespace Drupal\user\Tests;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;
/**
* Tests case for user signatures.
*
* @group user
*/
class UserSignatureTest extends WebTestBase {
use CommentTestTrait;
/**
* A regular user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* User with admin privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Filtered HTML format.
*
* @var \Drupal\filter\FilterFormatInterface
*/
protected $filteredHtmlFormat;
/**
* Full HTML format.
*
* @var \Drupal\filter\FilterFormatInterface
*/
protected $fullHtmlFormat;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'comment', 'field_ui');
protected function setUp() {
parent::setUp();
// Enable user signatures.
$this->config('user.settings')->set('signatures', 1)->save();
// Create Basic page node type.
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
// Add a comment field with commenting enabled by default.
$this->addDefaultCommentField('node', 'page');
// Prefetch and create text formats.
$this->filteredHtmlFormat = entity_create('filter_format', array(
'format' => 'filtered_html_format',
'name' => 'Filtered HTML',
'weight' => -1,
'filters' => array(
'filter_html' => array(
'module' => 'filter',
'status' => TRUE,
'settings' => array(
'allowed_html' => '<a> <em> <strong>',
),
),
),
));
$this->filteredHtmlFormat->save();
$this->fullHtmlFormat = entity_create('filter_format', array(
'format' => 'full_html',
'name' => 'Full HTML',
));
$this->fullHtmlFormat->save();
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array($this->filteredHtmlFormat->getPermissionName()));
// Create regular and administrative users.
$this->webUser = $this->drupalCreateUser(array('post comments'));
$admin_permissions = array('post comments', 'administer comments', 'administer user form display', 'administer account settings');
foreach (filter_formats() as $format) {
if ($permission = $format->getPermissionName()) {
$admin_permissions[] = $permission;
}
}
$this->adminUser = $this->drupalCreateUser($admin_permissions);
}
/**
* Test that a user can change their signature format and that it is respected
* upon display.
*/
function testUserSignature() {
$node = $this->drupalCreateNode(array(
'body' => array(
0 => array(
'value' => $this->randomMachineName(32),
'format' => 'full_html',
),
),
));
// Verify that user signature field is not displayed on registration form.
$this->drupalGet('user/register');
$this->assertNoText(t('Signature'));
// Log in as a regular user and create a signature.
$this->drupalLogin($this->webUser);
$signature_text = "<h1>" . $this->randomMachineName() . "</h1>";
$edit = array(
'signature[value]' => $signature_text,
);
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
// Verify that values were stored.
$this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.');
// Verify that the user signature's text format's cache tag is absent.
$this->drupalGet('node/' . $node->id());
$this->assertTrue(!in_array('filter_format:filtered_html_format', explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'))));
// Create a comment.
$edit = array();
$edit['subject[0][value]'] = $this->randomMachineName(8);
$edit['comment_body[0][value]'] = $this->randomMachineName(16);
$this->drupalPostForm('comment/reply/node/' . $node->id() .'/comment', $edit, t('Preview'));
$this->drupalPostForm(NULL, array(), t('Save'));
// Get the comment ID. (This technique is the same one used in the Comment
// module's CommentTestBase test case.)
preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
$comment_id = $match[1];
// Log in as an administrator and edit the comment to use Full HTML, so
// that the comment text itself is not filtered at all.
$this->drupalLogin($this->adminUser);
$edit['comment_body[0][format]'] = $this->fullHtmlFormat->id();
$this->drupalPostForm('comment/' . $comment_id . '/edit', $edit, t('Save'));
// Assert that the signature did not make it through unfiltered.
$this->drupalGet('node/' . $node->id());
$this->assertNoRaw($signature_text, 'Unfiltered signature text not found.');
$this->assertRaw(check_markup($signature_text, $this->filteredHtmlFormat->id()), 'Filtered signature text found.');
// Verify that the user signature's text format's cache tag is present.
$this->drupalGet('node/' . $node->id());
$this->assertTrue(in_array('config:filter.format.filtered_html_format', explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'))));
// Verify the signature field is available on Manage form display page.
$this->config('user.settings')->set('signatures', 0)->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
$this->drupalGet('admin/config/people/accounts/form-display');
$this->assertNoText('Signature settings');
$this->drupalPostForm('admin/config/people/accounts', array('user_signatures' => TRUE), t('Save configuration'));
$this->drupalGet('admin/config/people/accounts/form-display');
$this->assertText('Signature settings');
}
}
......@@ -139,14 +139,6 @@ function testValidation() {
$this->assertEqual($violations[0]->getMessage(), t('!name field is required.', array('!name' => String::placeholder($user->getFieldDefinition('mail')->getLabel()))));
$user->set('mail', 'someone@example.com');
$user->set('signature', $this->randomString(256));
$this->assertLengthViolation($user, 'signature', 255);
$user->set('signature', NULL);
$user->set('signature_format', $this->randomString(32));
$this->assertAllowedValuesViolation($user, 'signature_format');
$user->set('signature_format', NULL);
$user->set('timezone', $this->randomString(33));
$this->assertLengthViolation($user, 'timezone', 32, 2, 1);
$user->set('timezone', 'invalid zone');
......
......@@ -95,8 +95,6 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_
case 'preferred_langcode':
case 'preferred_admin_langcode':
case 'signature':
case 'signature_format':
case 'timezone':
case 'mail':
// Allow view access to own mail address and other personalization
......
......@@ -86,44 +86,6 @@ public function setPassword($password);
*/
public function setEmail($mail);
/**
* Returns the user signature.
*
* @todo: Convert this to a configurable field.
*
* @return string
* The signature text.
*/
public function getSignature();
/**
* Sets the user signature.
*
* @param string $signature
* The new signature text of the user.
*
* @return $this
*/
public function setSignature($signature);
/**
* Returns the signature format.
*
* @return string
* Name of the filter format.
*/
public function getSignatureFormat();
/**
* Sets the signature format.
*
* @param string $signature_format
* The name of the new filter format.
*
* @return $this
*/
public function setSignatureFormat($signature_format);
/**
* Returns the creation time of the user as a UNIX timestamp.
*
......
......@@ -218,24 +218,6 @@ public function getViewsData() {
),
);
unset($data['users_field_data']['signature']);
unset($data['users_field_data']['signature_format']);
if (\Drupal::moduleHandler()->moduleExists('filter')) {