Commit 54882e1e authored by Vinicius Costa's avatar Vinicius Costa Committed by De Araujo, Renato [CONBR Non-J&J]
Browse files

Issue #3319544 by viniciuscosta, roberttabigue, RenatoG: Make a Modal on 4.x...

Issue #3319544 by viniciuscosta, roberttabigue, RenatoG: Make a Modal on 4.x version to let users know about the 5.x version that is ready to D10
parent 342d5f16
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ use Drupal\modal_page\Helper\ModalPageFieldHelper;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\user\Entity\Role;
use Drupal\modal_page\Entity\Modal;

// Modal Page install helper functions.
include_once __DIR__ . '/includes/modal_page.install.inc';
@@ -27,6 +28,9 @@ function modal_page_install() {
    '@modal_page_settings' => Url::fromRoute('modal_page.settings')->toString(),
  ]));

  // Show message about the new version.
  _modal_page_show_message_modal_version_5();

}

/**
@@ -657,10 +661,51 @@ function modal_page_update_400013() {
  }
}

/**
 * Insert a Modal with new Release Information.
 */
function modal_page_update_400014() {

  _modal_page_show_message_modal_version_5();

}

// -----------------------------------------------------------------------------
// Auxiliar Methods. @codingStandardsIgnoreLine
// -----------------------------------------------------------------------------

/**
 * Create Modal about version 5.
 */
function _modal_page_show_message_modal_version_5() {

  $label = t('Modal 5 is available');

  $body = '<p>' . t('This new version is Ready to Drupal 10!') . '</p>';

  $body .= '<p>' . t('Update Modal and Enjoy') . '</p>';

  // @codingStandardsIgnoreLine
  $body .= '<p>' . t('If liked, please give us a') . ' <a href="https://www.drupal.org/project/modal_page" target="blank">' . t('star') . '</a> :)</p>';

  $type = 'page';
  $pages = '/admin/*';

  $modal = Modal::create([
    'id' => 'modal_page_5_available_to_drupal10',
  ]);

  $modal->setLabel($label);
  $modal->setBody($body);
  $modal->setType($type);
  $modal->setPages($pages);

  $modal->save();

  \Drupal::service('cache.render')->invalidateAll();

}

/**
 * Create the field published.
 */
+23 −8
Original line number Diff line number Diff line
@@ -227,8 +227,8 @@ function modal_page_entity_presave(EntityInterface $entity) {
 */
function modal_page_modal_submit($modal, $modal_state, $modal_id) {

  // If isn't the Modal for welcome, skip.
  if ($modal_id != 'thank_you_for_installing_modal_page') {
  // If isn't the Modal for welcome or Modal Update, skip.
  if ($modal_id != 'thank_you_for_installing_modal_page' && $modal_id != 'modal_page_5_available_to_drupal10') {
    return FALSE;
  }

@@ -240,13 +240,28 @@ function modal_page_modal_submit($modal, $modal_state, $modal_id) {
  // Delete the Modal used on welcome Message.
  $modal->delete();

  // Delete cookie for welcome Modal.
  if (!empty(\Drupal::service('request_stack')->getCurrentRequest()->cookies->get('hide_modal_id_thank_you_for_installing_modal_page'))) {
  _modal_page_delete_cookie('please_do_not_show_again_modal_id_thank_you_for_installing_modal_page');

  _modal_page_delete_cookie('please_do_not_show_again_modal_id_modal_page_5_available_to_drupal10');

}

/**
 * Auxiliary Method to delete cookie().
 */
function _modal_page_delete_cookie($cookie_id) {

  // If there is no cookie, skip.
  if (empty(\Drupal::service('request_stack')->getCurrentRequest()->cookies->get($cookie_id))) {
    return;
  }

  // Delete cookie.
  $response = new Response();
    $cookie = new Cookie('hide_modal_id_thank_you_for_installing_modal_page', '', time() - 3600, '/', NULL, FALSE);
  $cookie = new Cookie($cookie_id, '', time() - 3600, '/', NULL, FALSE);
  $response->headers->setCookie($cookie);
  $response->send();
  }

}

/**
+9 −1
Original line number Diff line number Diff line
@@ -114,8 +114,16 @@ class ModalForm extends EntityForm {
    ];

    $body = $modal->getBody();

    if (empty($body['value'])) {
      $body['value'] = '';

      $bodyValue = '';

      if (is_string($body)) {
        $bodyValue = $body;
      }
      $body = [];
      $body['value'] = $bodyValue;
    }
    // Drupal controls the default format value.
    if (empty($body['format'])) {