Unverified Commit 8bc240bb authored by jibran's avatar jibran Committed by jibran

Issue #2820976 by jibran, nehakhadke: $this->t() should be used instead of t() for Drupal 8 version

parent 53b1df59
......@@ -2,6 +2,7 @@
namespace Drupal\contact_storage\Plugin\Field\FieldType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\options\Plugin\Field\FieldType\ListItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
......@@ -25,7 +26,7 @@ class OptionsEmailItem extends ListItemBase {
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Text value'))
->setLabel(new TranslatableMarkup('Text value'))
->addConstraint('Length', ['max' => 255])
->setRequired(TRUE);
......@@ -53,12 +54,12 @@ class OptionsEmailItem extends ListItemBase {
* {@inheritdoc}
*/
protected function allowedValuesDescription() {
$description = '<p>' . t('The possible values this field can contain. Enter one value per line, in the format key|label|emails.');
$description .= '<br/>' . t('"key" is the message that is added to the body of the message.');
$description .= '<br/>' . t('"label" is the value displayed in the dropdown menu on the contact form.');
$description .= '<br/>' . t('"emails" are the email addresses to add to the recipients list (each separated by a comma).');
$description = '<p>' . $this->t('The possible values this field can contain. Enter one value per line, in the format key|label|emails.');
$description .= '<br/>' . $this->t('"key" is the message that is added to the body of the message.');
$description .= '<br/>' . $this->t('"label" is the value displayed in the dropdown menu on the contact form.');
$description .= '<br/>' . $this->t('"emails" are the email addresses to add to the recipients list (each separated by a comma).');
$description .= '</p>';
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
$description .= '<p>' . $this->t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
return $description;
}
......@@ -133,6 +134,7 @@ class OptionsEmailItem extends ListItemBase {
* {@inheritdoc}
*/
public function getSettableOptions(AccountInterface $account = NULL) {
$allowed_options_keys = [];
$allowed_options = $this->getOptionsAllowedValues();
// Each option is currently an array containing the value and emails, keyed
// with the key defined by the user. Remove the array to keep only the key.
......
......@@ -43,17 +43,17 @@ class BulkFormTest extends ContactStorageTestBase {
// Create first valid contact form.
$mail = 'simpletest@example.com';
$this->addContactForm('test_id', 'test_label', $mail, TRUE);
$this->assertText(t('Contact form test_label has been added.'));
$this->assertText('Contact form test_label has been added.');
$this->drupalLogout();
// Ensure that anonymous can submit site-wide contact form.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, ['access site-wide contact form']);
$this->drupalGet('contact');
$this->assertText(t('Your email address'));
$this->assertText('Your email address');
// Submit contact form few times.
for ($i = 1; $i <= 5; $i++) {
$this->submitContact($this->randomMachineName(), $mail, $this->randomMachineName(), 'test_id', $this->randomMachineName());
$this->assertText(t('Your message has been sent.'));
$this->assertText('Your message has been sent.');
}
}
......@@ -69,7 +69,7 @@ class BulkFormTest extends ContactStorageTestBase {
$elements = $this->xpath('//select[@id="edit-action"]//option');
$this->assertIdentical(count($elements), 1, 'All contact message operations are found.');
$this->drupalPostForm('test-contact-message-bulk-form', [], t('Apply to selected items'));
$this->assertText(t('No message selected.'));
$this->assertText('No message selected.');
}
}
......@@ -74,16 +74,16 @@ class ContactStorageTest extends ContactStorageTestBase {
// Create first valid contact form.
$mail = 'simpletest@example.com';
$this->addContactForm('test_id', 'test_label', $mail, TRUE);
$this->assertText(t('Contact form test_label has been added.'));
$this->assertText('Contact form test_label has been added.');
// Ensure that anonymous can submit site-wide contact form.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, ['access site-wide contact form']);
$this->drupalLogout();
$this->drupalGet('contact');
$this->assertText(t('Your email address'));
$this->assertText('Your email address');
$this->assertNoText(t('Form'));
$this->submitContact('Test_name', $mail, 'Test_subject', 'test_id', 'Test_message');
$this->assertText(t('Your message has been sent.'));
$this->assertText('Your message has been sent.');
// Verify that only 1 message has been sent (by default, the "Send a copy
// to yourself" option is disabled.
......@@ -372,7 +372,7 @@ class ContactStorageTest extends ContactStorageTestBase {
public function testMaximumSubmissionLimit() {
// Create a new contact form with a maximum submission limit of 2.
$this->addContactForm('test_id_3', 'test_label', 'simpletest@example.com', FALSE, ['contact_storage_maximum_submissions_user' => 2]);
$this->assertText(t('Contact form test_label has been added.'));
$this->assertText('Contact form test_label has been added.');
// Sends 2 messages with "Send yourself a copy" option activated, shouldn't
// reach the limit even if 2 messages are sent twice.
......@@ -383,14 +383,14 @@ class ContactStorageTest extends ContactStorageTestBase {
'copy' => 'checked',
];
$this->drupalPostForm(NULL, $edit, t('Send message'));
$this->assertText(t('Your message has been sent.'));
$this->assertText('Your message has been sent.');
$this->drupalGet('contact/test_id_3');
$this->drupalPostForm(NULL, $edit, t('Send message'));
$this->assertText(t('Your message has been sent.'));
$this->assertText('Your message has been sent.');
// Try accessing the form after the limit has been reached.
$this->drupalGet('contact/test_id_3');
$this->assertText(t('You have reached the maximum submission limit of 2 for this form.'));
$this->assertText('You have reached the maximum submission limit of 2 for this form.');
}
/**
......@@ -399,7 +399,7 @@ class ContactStorageTest extends ContactStorageTestBase {
public function testAutoReplyField() {
// Create a new contact form with an auto-reply.
$this->addContactForm('test_auto_reply_id_1', 'test_auto_reply_label_1', 'simpletest@example.com', TRUE, ['reply[value]' => "auto_reply_1\nsecond_line"]);
$this->assertText(t('Contact form test_auto_reply_label_1 has been added.'));
$this->assertText('Contact form test_auto_reply_label_1 has been added.');
// Verify that the auto-reply shows up in the field and only offers
// one format (plain text), since html e-mails are disabled.
......
......@@ -64,7 +64,7 @@ class ContactViewBuilderTest extends ContactStorageTestBase {
// Create first valid contact form.
$mail = 'simpletest@example.com';
$this->addContactForm('test_id', 'test_label', $mail, TRUE);
$this->assertText(t('Contact form test_label has been added.'));
$this->assertText('Contact form test_label has been added.');
$field_name = 'contact';
$entity_type = 'node';
......@@ -125,9 +125,9 @@ class ContactViewBuilderTest extends ContactStorageTestBase {
$node = $this->drupalGetNodeByTitle($edit[$title_key]);
$this->drupalGet('node/' . $node->id());
// Some fields should be present.
$this->assertText(t('Your email address'));
$this->assertText(t('Subject'));
$this->assertText(t('Message'));
$this->assertText('Your email address');
$this->assertText('Subject');
$this->assertText('Message');
$this->assertFieldByName('subject[0][value]');
$this->assertFieldByName('message[0][value]');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment