deactivated vuejs for simplenews pages = fixed unsubscribe bug

This commit is contained in:
Bachir Soussi Chiadmi 2022-03-31 20:27:59 +02:00
parent 1f6d1398c2
commit 2b48c867ea
13 changed files with 295 additions and 30 deletions

View File

@ -139,6 +139,7 @@
"drupal/restui": "^1.16", "drupal/restui": "^1.16",
"drupal/role_delegation": "^1.1", "drupal/role_delegation": "^1.1",
"drupal/role_expire": "^2.0", "drupal/role_expire": "^2.0",
"drupal/rules": "3.x-dev@dev",
"drupal/search_api": "^1.19", "drupal/search_api": "^1.19",
"drupal/search_api_autocomplete": "^1.2", "drupal/search_api_autocomplete": "^1.2",
"drupal/search_api_page": "^1.x-dev", "drupal/search_api_page": "^1.x-dev",

59
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "28c5d047d6b22eec98aba7c5c09e2978", "content-hash": "1b136647bf70d7d1c350f23bced3287a",
"packages": [ "packages": [
{ {
"name": "alchemy/zippy", "name": "alchemy/zippy",
@ -12236,6 +12236,62 @@
"source": "https://git.drupalcode.org/project/role_expire" "source": "https://git.drupalcode.org/project/role_expire"
} }
}, },
{
"name": "drupal/rules",
"version": "dev-3.x",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/rules.git",
"reference": "ec0b4dbc1fb9a0b59cac43908f1af5137e946dea"
},
"require": {
"drupal/core": "^9.1 || ^10",
"drupal/typed_data": "^1.0"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-3.x": "3.x-dev"
},
"drupal": {
"version": "8.x-3.x-dev",
"datestamp": "1645514637",
"security-coverage": {
"status": "not-covered",
"message": "Dev releases are not covered by Drupal security advisories."
}
},
"drush": {
"services": {
"drush.services.yml": "^9 || ^10"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "TR",
"homepage": "https://www.drupal.org/user/202830"
},
{
"name": "fago",
"homepage": "https://www.drupal.org/user/16747"
},
{
"name": "klausi",
"homepage": "https://www.drupal.org/user/262198"
}
],
"description": "React on events and conditionally evaluate actions.",
"homepage": "https://www.drupal.org/project/rules",
"support": {
"source": "https://git.drupalcode.org/project/rules",
"issues": "https://www.drupal.org/project/issues/rules"
}
},
{ {
"name": "drupal/search_api", "name": "drupal/search_api",
"version": "1.23.0", "version": "1.23.0",
@ -25086,6 +25142,7 @@
"drupal/mimemail": 20, "drupal/mimemail": 20,
"drupal/profile": 20, "drupal/profile": 20,
"drupal/redirect": 20, "drupal/redirect": 20,
"drupal/rules": 20,
"drupal/search_api_page": 20, "drupal/search_api_page": 20,
"drupal/select_translation": 20, "drupal/select_translation": 20,
"drupal/session_limit": 10, "drupal/session_limit": 10,

View File

@ -172,6 +172,7 @@ module:
restui: 0 restui: 0
role_delegation: 0 role_delegation: 0
role_expire: 0 role_expire: 0
rules: 0
search_api: 0 search_api: 0
search_api_db: 0 search_api_db: 0
search_api_solr: 0 search_api_solr: 0

View File

@ -0,0 +1,36 @@
uuid: 3ca6603a-2a65-4276-9cc7-50b1a9a6a7f9
langcode: en
status: true
dependencies:
enforced:
module:
- filter
- rules
_core:
default_config_hash: VrFjOQn2l2n6baaj2Z6IkYt9OdtsLjYPUVg7HgkkGLU
name: 'Restricted HTML'
format: restricted_html
weight: 1
filters:
filter_html:
id: filter_html
provider: filter
status: true
weight: -10
settings:
allowed_html: '<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>'
filter_html_help: true
filter_html_nofollow: false
filter_autop:
id: filter_autop
provider: filter
status: true
weight: 0
settings: { }
filter_url:
id: filter_url
provider: filter
status: true
weight: 0
settings:
filter_url_length: 72

View File

@ -0,0 +1 @@
name: 'HTML restreint'

View File

@ -0,0 +1,8 @@
_core:
default_config_hash: ZKaBtyYFEhfwE4xVP-khSsZabdsN3NSjwOfzaZksez0
system_log:
log_level: warning
debug_log:
enabled: false
system_debug: false
log_level: debug

View File

@ -0,0 +1,17 @@
uuid: bd0b5826-cc41-44ad-b62a-e342aa06f0ce
langcode: en
status: true
dependencies:
module:
- rules
title: 'Default cron handler'
id: rules_cron
weight: 0
module: rules
callback: rules_cron
scheduler:
id: simple
launcher:
id: serial
logger:
id: database

View File

@ -3,6 +3,7 @@ langcode: fr
status: true status: true
dependencies: dependencies:
config: config:
- filter.format.restricted_html
- filter.format.wysiwyg - filter.format.wysiwyg
- rest.resource.user_registration - rest.resource.user_registration
module: module:
@ -35,6 +36,7 @@ permissions:
- 'execute materio persisted graphql requests' - 'execute materio persisted graphql requests'
- 'restful post user_registration' - 'restful post user_registration'
- 'subscribe to newsletters' - 'subscribe to newsletters'
- 'use text format restricted_html'
- 'use text format wysiwyg' - 'use text format wysiwyg'
- 'view body' - 'view body'
- 'view commerce_product' - 'view commerce_product'

View File

@ -3,8 +3,11 @@
namespace Drupal\materio_simplenews\Form; namespace Drupal\materio_simplenews\Form;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\simplenews\Form\SubscriptionsFormBase; use Drupal\simplenews\Form\SubscriptionsFormBase;
// ! NOT USED ANY MORE
/** /**
* Configure simplenews subscriptions of the logged user. * Configure simplenews subscriptions of the logged user.
*/ */
@ -19,6 +22,27 @@ class MaterioSubscriptionsBlockForm extends SubscriptionsFormBase {
*/ */
public $message; public $message;
/**
* The newsletters available to select from.
*
* @var string[]
*/
protected $newsletterIds = [];
/**
* The default newsletters.
*
* @var string[]
*/
protected $defaultNewsletterIds = [];
/**
* Whether to show "Manage existing" link.
*
* @var bool
*/
protected $showManage = FALSE;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -34,23 +58,95 @@ class MaterioSubscriptionsBlockForm extends SubscriptionsFormBase {
*/ */
public function setUniqueId($id) { public function setUniqueId($id) {
$this->uniqueId = $id; $this->uniqueId = $id;
return $this;
}
/**
* Set message.
*
* @param string $message
* Message to use as description for the block.
*
* @return $this
*/
public function setMessage($message) {
$this->message = $message;
return $this;
}
/**
* Set the newsletters available to select from.
*
* @param string[] $newsletters
* Newsletter IDs available to select from.
* @param string[] $defaults
* (optional) Newsletter IDs selected by default.
*
* @return $this
*/
public function setNewsletterIds(array $newsletters, array $defaults = []) {
$visible = array_keys(simplenews_newsletter_get_visible());
// Exclude newsletters already subscribed.
$subscribed = $this->entity->getSubscribedNewsletterIds();
$this->newsletterIds = array_diff(array_intersect($newsletters, $visible), $subscribed);
$this->defaultNewsletterIds = array_diff(array_intersect($defaults, $visible), $subscribed);
return $this;
}
/**
* Returns the newsletters available to select from.
*
* @return string[]
* The newsletter IDs available to select from, as an indexed array.
*/
public function getNewsletterIds() {
return $this->newsletterIds;
}
/**
* Set whether to show "Manage existing" link.
*
* @param bool $show
* TRUE to show "Manage existing" link, FALSE to hide.
*
* @return $this
*/
public function setShowManage($show) {
$this->showManage = $show;
return $this;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function form(array $form, FormStateInterface $form_state) { public function form(array $form, FormStateInterface $form_state) {
// Hide subscription widget if only one newsletter available. $this->getSubscriptionWidget($form_state)->setAvailableNewsletterIds($this->newsletterIds);
if (count($this->getNewsletters()) == 1) {
$this->getSubscriptionWidget($form_state)->setHidden(); if (!$form_state->getUserInput()) {
// Set defaults.
foreach ($this->defaultNewsletterIds as $newsletter_id) {
$this->entity->subscribe($newsletter_id, SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, 'website');
}
} }
$form = parent::form($form, $form_state); $form = parent::form($form, $form_state);
$form['subscriptions']['widget']['#title'] = $this->t('Manage your newsletter subscriptions');
$form['subscriptions']['widget']['#description'] = $this->t('Select the newsletter(s) to which you want to subscribe.');
$hidden_default_ids = array_diff($this->defaultNewsletterIds, $this->getNewsletterIds());
$form['subscriptions']['widget']['#required'] = empty($hidden_default_ids);
$form['subscriptions']['widget']['#access'] = !empty($this->newsletterIds);
$form['message'] = array(
'#type' => 'item', if (!$this->newsletterIds && !$this->defaultNewsletterIds) {
'#markup' => $this->message, $this->message = $this->t('You are already subscribed');
); }
if ($this->message) {
$form['message'] = [
'#type' => 'item',
'#markup' => $this->message,
];
}
unset($form['subscriptions']['widget']['#title']); unset($form['subscriptions']['widget']['#title']);
unset($form['subscriptions']['widget']['#description']); unset($form['subscriptions']['widget']['#description']);
@ -63,41 +159,84 @@ class MaterioSubscriptionsBlockForm extends SubscriptionsFormBase {
unset($form['mail']['widget'][0]['value']['#title']); unset($form['mail']['widget'][0]['value']['#title']);
unset($form['mail']['widget'][0]['value']['#description']); unset($form['mail']['widget'][0]['value']['#description']);
$mailvalue = $form['mail']['widget'][0];
$test='test';
return $form; return $form;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function actions(array $form, FormStateInterface $form_state) { protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state); $actions = parent::actions($form, $form_state);
$actions[static::SUBMIT_UPDATE]['#value'] = $this->t('Update');
$actions['submit']['#value'] = $this->t('Subscribe');
if (!$this->newsletterIds && !$this->defaultNewsletterIds) {
$actions['submit']['#attributes']['disabled'] = TRUE;
}
if ($this->showManage) {
$user = \Drupal::currentUser();
$link = $user->isAuthenticated() ? Url::fromRoute('simplenews.newsletter_subscriptions_user', ['user' => $user->id()]) : Url::fromRoute('simplenews.newsletter_validate');
$actions['manage'] = [
'#title' => $this->t('Manage existing'),
'#type' => 'link',
'#url' => $link,
];
}
return $actions; return $actions;
} }
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$mail = $form_state->getValue(['mail', 0, 'value']);
if ($this->entity->isNew() && $subscriber = Subscriber::loadByMail($mail)) {
$this->setEntity($subscriber);
}
parent::validateForm($form, $form_state);
$mail = $form_state->getValue(['mail', 0, 'value']);
// Cannot subscribe blocked users.
if (($user = user_load_by_mail($mail)) && $user->isBlocked()) {
$message = $this->t('The email address %mail belongs to a blocked user.', ['%mail' => $mail]);
$form_state->setErrorByName('mail', $message);
}
}
/**
* Submit callback that subscribes to selected newsletters.
*
* @param array $form
* The form structure.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
public function submitExtra(array $form, FormStateInterface $form_state) {
/** @var \Drupal\simplenews\Subscription\SubscriptionManagerInterface $subscription_manager */
$subscription_manager = \Drupal::service('simplenews.subscription_manager');
// Subscribe the selected newsletters and any defaults that are hidden.
$selected_ids = $this->extractNewsletterIds($form_state, TRUE);
$hidden_default_ids = array_diff($this->defaultNewsletterIds, $this->getNewsletterIds());
foreach (array_unique(array_merge($selected_ids, $hidden_default_ids)) as $newsletter_id) {
$subscription_manager->subscribe($this->entity->getMail(), $newsletter_id, NULL, 'website');
}
$sent = $subscription_manager->sendConfirmations();
$this->messenger()->addMessage($this->getSubmitMessage($form_state, $sent));
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getSubmitMessage(FormStateInterface $form_state, $op, $confirm) { protected function getSubmitMessage(FormStateInterface $form_state, $confirm) {
switch ($op) { if ($confirm) {
case static::SUBMIT_UPDATE: return $this->t('You will receive a confirmation e-mail shortly containing further instructions on how to complete your subscription.');
return $this->t('The newsletter subscriptions for %mail have been updated.', array('%mail' => $form_state->getValue('mail')[0]['value']));
case static::SUBMIT_SUBSCRIBE:
if ($confirm) {
return $this->t('You will receive a confirmation e-mail shortly containing further instructions on how to complete your subscription.');
}
return $this->t('You have been subscribed.');
case static::SUBMIT_UNSUBSCRIBE:
if ($confirm) {
return $this->t('You will receive a confirmation e-mail shortly containing further instructions on how to cancel your subscription.');
}
return $this->t('You have been unsubscribed.');
} }
return $this->t('You have been subscribed.');
} }
} }

View File

@ -12,6 +12,8 @@ use Drupal\Core\Session\AccountInterface;
use Drupal\simplenews\Entity\Subscriber; use Drupal\simplenews\Entity\Subscriber;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
// ! NOT USED ANY MORE
/** /**
* Provides an 'Simplenews subscription' block with all available newsletters and an email field. * Provides an 'Simplenews subscription' block with all available newsletters and an email field.
* *

File diff suppressed because one or more lines are too long

View File

@ -101,7 +101,8 @@ export let _v_sitebranding_block, _v_user_block, _v_header_menu,
drupalDecoupled.route_name.indexOf('entity.webform.canonical') !== -1 || drupalDecoupled.route_name.indexOf('entity.webform.canonical') !== -1 ||
drupalDecoupled.route_name.indexOf('entity.webform.confirmation') !== -1 || drupalDecoupled.route_name.indexOf('entity.webform.confirmation') !== -1 ||
drupalDecoupled.route_name.indexOf('materio_expo.qr_controller_getfile') !== -1 || drupalDecoupled.route_name.indexOf('materio_expo.qr_controller_getfile') !== -1 ||
(drupalDecoupled.route_name === 'entity.node.canonical' && drupalDecoupled.entity_bundle === 'simplenews_issue') (drupalDecoupled.route_name === 'entity.node.canonical' && drupalDecoupled.entity_bundle === 'simplenews_issue') ||
drupalDecoupled.route_name.indexOf('simplenews') !== -1
) { ) {
console.debug('NO VUEJS') console.debug('NO VUEJS')
return true return true