Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -43,3 +43,14 @@ contact.settings:
|
|||
user_default_enabled:
|
||||
type: boolean
|
||||
label: 'Personal contact form enabled by default'
|
||||
|
||||
migrate.source.d6_contact_settings:
|
||||
type: migrate_source_sql
|
||||
label: 'Drupal 6 contact settings'
|
||||
mapping:
|
||||
variables:
|
||||
type: sequence
|
||||
label: 'Variables'
|
||||
sequence:
|
||||
type: string
|
||||
label: 'Variable'
|
||||
|
|
|
@ -143,7 +143,7 @@ function contact_mail($key, &$message, $params) {
|
|||
$message['subject'] .= t('[!form] !subject', $variables, $options);
|
||||
$message['body'][] = t("!sender-name (!sender-url) sent a message using the contact form at !form-url.", $variables, $options);
|
||||
$build = entity_view($contact_message, 'mail', $language->getId());
|
||||
$message['body'][] = \Drupal::service('renderer')->renderPlain($build);
|
||||
$message['body'][] = (string) \Drupal::service('renderer')->renderPlain($build);
|
||||
break;
|
||||
|
||||
case 'page_autoreply':
|
||||
|
@ -162,7 +162,7 @@ function contact_mail($key, &$message, $params) {
|
|||
$message['body'][] = t("!sender-name (!sender-url) has sent you a message via your contact form at !site-name.", $variables, $options);
|
||||
$message['body'][] = t("If you don't want to receive such emails, you can change your settings at !recipient-edit-url.", $variables, $options);
|
||||
$build = entity_view($contact_message, 'mail', $language->getId());
|
||||
$message['body'][] = \Drupal::service('renderer')->renderPlain($build);
|
||||
$message['body'][] = (string) \Drupal::service('renderer')->renderPlain($build);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ contact.site_page:
|
|||
requirements:
|
||||
_permission: 'access site-wide contact form'
|
||||
|
||||
contact.site_page_form:
|
||||
entity.contact_form.canonical:
|
||||
path: '/contact/{contact_form}'
|
||||
defaults:
|
||||
_title: 'Contact'
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
id: d6_contact_category
|
||||
label: Drupal 6 contact category configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: d6_contact_category
|
||||
process:
|
||||
id:
|
||||
-
|
||||
plugin: machine_name
|
||||
source: category
|
||||
-
|
||||
plugin: dedupe_entity
|
||||
entity_type: user_role
|
||||
field: cid
|
||||
length: 32
|
||||
label: category
|
||||
recipients: recipients
|
||||
reply: reply
|
||||
weight: weight
|
||||
destination:
|
||||
plugin: entity:contact_form
|
|
@ -0,0 +1,22 @@
|
|||
id: d6_contact_settings
|
||||
label: Drupal 6 contact configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: d6_contact_settings
|
||||
variables:
|
||||
- contact_default_status
|
||||
- contact_hourly_threshold
|
||||
process:
|
||||
user_default_enabled: contact_default_status
|
||||
'flood/limit': contact_hourly_threshold
|
||||
default_form:
|
||||
plugin: migration
|
||||
migration: d6_contact_category
|
||||
source: default_category
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: contact.settings
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_contact_category
|
|
@ -112,8 +112,8 @@ class ContactFormEditForm extends EntityForm implements ContainerInjectionInterf
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate(array $form, FormStateInterface $form_state) {
|
||||
parent::validate($form, $form_state);
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
parent::validateForm($form, $form_state);
|
||||
|
||||
// Validate and each email recipient.
|
||||
$recipients = explode(',', $form_state->getValue('recipients'));
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Drupal\contact;
|
|||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of contact form entities.
|
||||
|
@ -32,13 +33,14 @@ class ContactFormListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['form'] = $this->getLabel($entity);
|
||||
// Special case the personal form.
|
||||
if ($entity->id() == 'personal') {
|
||||
$row['form'] = $this->getLabel($entity);
|
||||
$row['recipients'] = t('Selected user');
|
||||
$row['selected'] = t('No');
|
||||
}
|
||||
else {
|
||||
$row['form'] = $entity->link(NULL, 'canonical');
|
||||
$row['recipients'] = SafeMarkup::checkPlain(implode(', ', $entity->getRecipients()));
|
||||
$default_form = \Drupal::config('contact.settings')->get('default_form');
|
||||
$row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No'));
|
||||
|
|
|
@ -36,6 +36,7 @@ use Drupal\contact\ContactFormInterface;
|
|||
* "delete-form" = "/admin/structure/contact/manage/{contact_form}/delete",
|
||||
* "edit-form" = "/admin/structure/contact/manage/{contact_form}",
|
||||
* "collection" = "/admin/structure/contact",
|
||||
* "canonical" = "/contact/{contact_form}",
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
|
|
|
@ -168,8 +168,8 @@ class MessageForm extends ContentEntityForm {
|
|||
$elements = parent::actions($form, $form_state);
|
||||
$elements['submit']['#value'] = $this->t('Send message');
|
||||
$elements['preview'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Preview'),
|
||||
'#validate' => array('::validate'),
|
||||
'#submit' => array('::submitForm', '::preview'),
|
||||
);
|
||||
return $elements;
|
||||
|
@ -187,10 +187,8 @@ class MessageForm extends ContentEntityForm {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate(array $form, FormStateInterface $form_state) {
|
||||
parent::validate($form, $form_state);
|
||||
|
||||
$message = $this->entity;
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
$message = parent::validateForm($form, $form_state);
|
||||
|
||||
// Check if flood control has been activated for sending emails.
|
||||
if (!$this->currentUser()->hasPermission('administer contact forms') && (!$message->isPersonal() || !$this->currentUser()->hasPermission('administer users'))) {
|
||||
|
@ -204,6 +202,8 @@ class MessageForm extends ContentEntityForm {
|
|||
)));
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,20 +231,4 @@ class MessageForm extends ContentEntityForm {
|
|||
$message->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function init(FormStateInterface $form_state) {
|
||||
$message = $this->entity;
|
||||
|
||||
// Make the message inherit the current content language unless specifically
|
||||
// set.
|
||||
if ($message->isNew() && !$message->langcode->value) {
|
||||
$language_content = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
|
||||
$message->langcode->value = $language_content->getId();
|
||||
}
|
||||
|
||||
parent::init($form_state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\contact\Plugin\migrate\source\d6\ContactCategory.
|
||||
*/
|
||||
|
||||
namespace Drupal\contact\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Drupal 6 contact category source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_contact_category",
|
||||
* source_provider = "contact"
|
||||
* )
|
||||
*/
|
||||
class ContactCategory extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('contact', 'c')
|
||||
->fields('c', array(
|
||||
'cid',
|
||||
'category',
|
||||
'recipients',
|
||||
'reply',
|
||||
'weight',
|
||||
'selected',
|
||||
)
|
||||
);
|
||||
$query->orderBy('cid');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$row->setSourceProperty('recipients', explode(',', $row->getSourceProperty('recipients')));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'cid' => $this->t('Primary Key: Unique category ID.'),
|
||||
'category' => $this->t('Category name.'),
|
||||
'recipients' => $this->t('Comma-separated list of recipient email addresses.'),
|
||||
'reply' => $this->t('Text of the auto-reply message.'),
|
||||
'weight' => $this->t("The category's weight."),
|
||||
'selected' => $this->t('Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['cid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\contact\Plugin\migrate\source\d6\ContactSettings.
|
||||
*/
|
||||
|
||||
namespace Drupal\contact\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\Variable;
|
||||
|
||||
/**
|
||||
* @MigrateSource(
|
||||
* id = "d6_contact_settings",
|
||||
* source_provider = "contact"
|
||||
* )
|
||||
*/
|
||||
class ContactSettings extends Variable {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function initializeIterator() {
|
||||
$default_category = $this->select('contact', 'c')
|
||||
->fields('c', array('cid'))
|
||||
->condition('selected', 1)
|
||||
->execute()
|
||||
->fetchField();
|
||||
return new \ArrayIterator(array($this->values() + array('default_category' => $default_category)));
|
||||
}
|
||||
|
||||
}
|
|
@ -250,10 +250,17 @@ class ContactSitewideTest extends WebTestBase {
|
|||
// Test field UI and field integration.
|
||||
$this->drupalGet('admin/structure/contact');
|
||||
|
||||
$view_link = $this->xpath('//table/tbody/tr/td/a[contains(@href, :href) and text()=:text]', [
|
||||
':href' => \Drupal::url('entity.contact_form.canonical', ['contact_form' => $contact_form]),
|
||||
':text' => $label,
|
||||
]
|
||||
);
|
||||
$this->assertTrue(!empty($view_link), 'Contact listing links to contact form.');
|
||||
|
||||
// Find out in which row the form we want to add a field to is.
|
||||
$i = 0;
|
||||
foreach($this->xpath('//table/tbody/tr') as $row) {
|
||||
if (((string)$row->td[0]) == $label) {
|
||||
if (((string) $row->td[0]->a) == $label) {
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\contact\Tests\Migrate\d6\MigrateContactCategoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\contact\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\contact\Entity\ContactForm;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Migrate contact categories to contact.form.*.yml.
|
||||
*
|
||||
* @group contact
|
||||
*/
|
||||
class MigrateContactCategoryTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('contact');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadDumps(['Contact.php']);
|
||||
$this->executeMigration('d6_contact_category');
|
||||
}
|
||||
|
||||
/**
|
||||
* The Drupal 6 contact categories to Drupal 8 migration.
|
||||
*/
|
||||
public function testContactCategory() {
|
||||
/** @var \Drupal\contact\Entity\ContactForm $contact_form */
|
||||
$contact_form = ContactForm::load('website_feedback');
|
||||
$this->assertIdentical('Website feedback', $contact_form->label());
|
||||
$this->assertIdentical(array('admin@example.com'), $contact_form->getRecipients());
|
||||
$this->assertIdentical('', $contact_form->getReply());
|
||||
$this->assertIdentical(0, $contact_form->getWeight());
|
||||
|
||||
$contact_form = ContactForm::load('some_other_category');
|
||||
$this->assertIdentical('Some other category', $contact_form->label());
|
||||
$this->assertIdentical(array('test@example.com'), $contact_form->getRecipients());
|
||||
$this->assertIdentical('Thanks for contacting us, we will reply ASAP!', $contact_form->getReply());
|
||||
$this->assertIdentical(1, $contact_form->getWeight());
|
||||
|
||||
$contact_form = ContactForm::load('a_category_much_longer_than_thir');
|
||||
$this->assertIdentical('A category much longer than thirty two characters', $contact_form->label());
|
||||
$this->assertIdentical(array('fortyninechars@example.com'), $contact_form->getRecipients());
|
||||
$this->assertIdentical('', $contact_form->getReply());
|
||||
$this->assertIdentical(2, $contact_form->getWeight());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\contact\Tests\Migrate\d6\MigrateContactConfigsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\contact\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade variables to contact.settings.yml.
|
||||
*
|
||||
* @group contact
|
||||
*/
|
||||
class MigrateContactConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('contact');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Add some id mappings for the dependent migrations.
|
||||
$id_mappings = array(
|
||||
'd6_contact_category' => array(
|
||||
array(array(1), array('website_feedback')),
|
||||
array(array(2), array('some_other_category')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->loadDumps(['Variable.php', 'Contact.php']);
|
||||
$this->executeMigration('d6_contact_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of contact variables to contact.settings.yml.
|
||||
*/
|
||||
public function testContactSettings() {
|
||||
$config = $this->config('contact.settings');
|
||||
$this->assertIdentical(true, $config->get('user_default_enabled'));
|
||||
$this->assertIdentical(3, $config->get('flood.limit'));
|
||||
$this->assertIdentical('some_other_category', $config->get('default_form'));
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), 'contact.settings', $config->get());
|
||||
}
|
||||
|
||||
}
|
|
@ -86,7 +86,7 @@ class ContactLinkTest extends ViewTestBase {
|
|||
// Disable contact link for no_contact.
|
||||
$this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE);
|
||||
// @todo Remove cache invalidation in https://www.drupal.org/node/2477903.
|
||||
Cache::invalidateTags($no_contact_account->getCacheTags());
|
||||
Cache::invalidateTags($no_contact_account->getCacheTagsToInvalidate());
|
||||
$this->drupalGet('test-contact-link');
|
||||
$this->assertContactLinks($accounts, array('root', 'admin'));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\contact\Unit\Plugin\migrate\source\d6\ContactCategoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\contact\Unit\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D6 contact category source plugin.
|
||||
*
|
||||
* @group contact
|
||||
*/
|
||||
class ContactCategoryTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\contact\Plugin\migrate\source\d6\ContactCategory';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'idlist' => array(),
|
||||
'source' => array(
|
||||
'plugin' => 'd6_contact_category',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'cid' => 1,
|
||||
'category' => 'contact category value 1',
|
||||
'recipients' => array('admin@example.com','user@example.com'),
|
||||
'reply' => 'auto reply value 1',
|
||||
'weight' => 0,
|
||||
'selected' => 0,
|
||||
),
|
||||
array(
|
||||
'cid' => 2,
|
||||
'category' => 'contact category value 2',
|
||||
'recipients' => array('admin@example.com','user@example.com'),
|
||||
'reply' => 'auto reply value 2',
|
||||
'weight' => 0,
|
||||
'selected' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
foreach ($this->expectedResults as $k => $row) {
|
||||
$this->databaseContents['contact'][$k] = $row;
|
||||
$this->databaseContents['contact'][$k]['recipients'] = implode(',', $row['recipients']);
|
||||
}
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue