Problem/Motivation

The media module requirements are double-escaped when there is a requirements issue.

Example here using the "Demo: Umami Food Magazine (Experimental)" installation profile

Requirements are double-escaped

Proposed resolution

Use inline template for the description.

Remaining tasks

Create follow-up to discuss weighting requirements.

Issue fork drupal-3113314

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Sivaji created an issue. See original summary.

sivaji_ganesh_jojodae’s picture

Issue summary: View changes
hardik_patel_12’s picture

StatusFileSize
new1.56 KB

Kindly review a patch.

hardik_patel_12’s picture

Status: Active » Needs review
sivaji_ganesh_jojodae’s picture

Status: Needs review » Needs work
Issue tags: +Novice
StatusFileSize
new125.03 KB

Patch #3 works great.

I would suggest putting the "FILE SYSTEM" error on the top. Because that eventually fixes the MEDIA SYSTEM public://media-icons/generic directory error automatically. I tried to set the weight on hook_requirements() but doesn't seem to work.

flip the order

mradcliffe’s picture

Version: 8.8.2 » 8.9.x-dev
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Novice

I'm not sure if flipping the order should be in scope of this issue. The weight is most likely going to be associated with the module/extension weight. I removed the Novice issue tag because I do not think there is enough information here for someone to pick up and work on with regard to requirements order.

I updated the version to 8.9.x. This would apply to the most recent version for development rather than a specific release.

I also found a related issue for inline template is used in requirements when using drupal console #3081572: Unexpected description format when parsing the unmet requirements message string.

sivaji_ganesh_jojodae’s picture

Okay, fine.

Able to set weight (like menu items) in the hook_requirements() might be a good feature request.

The directory public://media-icons/generic does not exist...

The file path in the error message seems not making much sense from the user standpoint.

naresh_bavaskar’s picture

Status: Needs review » Reviewed & tested by the community

#3 applied properly. LGTM + RTBC
Assuming set weight not covering in this issue. Thanks

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/media/media.install
@@ -58,6 +58,9 @@ function media_install() {
+  $requirements['media'] = [
+    'title' => t('Media system'),
+  ];

@@ -72,7 +75,14 @@ function media_requirements($phase) {
         $requirements['media']['description'] = $description;

This should be next to $requirements['media']['description'] = $description;

In fact this section deserves a little bit of a rework for clarity...

  if ($phase == 'install') {
    $error = NULL;
    $destination = 'public://media-icons/generic';
    \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
    if (!is_dir($destination)) {
      $error = t('The directory %directory does not exist.', ['%directory' => $destination]);
    }
    elseif(!is_writable($destination)) {
      $error = t('The directory %directory is not writable.', ['%directory' => $destination]);
    }
    if (isset($error)) {
      $description = t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', [':handbook_url' => 'https://www.drupal.org/server-permissions']);
      $description = [
        '#type' => 'inline_template',
        '#template' => '{{ error }} {{ description }}',
        '#context' => [
          'error' => $error,
          'description' => $description,
        ],
      ];
      $requirements['media'] = [
        'title' => t('Media system'),
        'description' => $description,
        'severity' => REQUIREMENT_ERROR,
      ];
    }
//... the rest of the code.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kishor_kolekar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.26 KB

I've re-rolled patch for 9.1

sivaji_ganesh_jojodae’s picture

Status: Needs review » Needs work

@alexpott, regarding,

In fact this section deserves a little bit of a rework for clarity...

that code block looks closer to system.install's hook_requirements(),

can you brief what kind of rework is there in your mind?

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Assigned: Unassigned » alexpott
Issue tags: +Bug Smash Initiative, +Needs subsystem maintainer review

For #12

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan’s picture

Component: system.module » media system

This has moved to \Drupal\media\Install\Requirements\MediaRequirements::getRequirements. It's also not in system.module so I'm updating the component.

I think now that this is in a much more isolated function we can use early returns for clarity. Something like this:

public static function getRequirements(): array {
  $requirements = [];
  $destination = 'public://media-icons/generic';
  \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
  $is_directory = is_dir($destination);
  $is_writable = is_writable($destination);
  if ($is_directory && $is_writable) {
    return $requirements;
  }
  $t_args = ['%directory' => $destination];
  $error = !$is_directory
    ? $this->t('The directory %directory does not exist.', $t_args)
    : $this->t('The directory %directory is not writable.', $t_args);

  // The rest of the inline template / description bits here.
}

mstrelan’s picture

Status: Needs work » Needs review
smustgrave’s picture

Assigned: alexpott » Unassigned
Status: Needs review » Needs work
Issue tags: -Needs subsystem maintainer review

Tried to ping in #core-development but no luck. Think good to unassign after all the years and since it moved to media maybe doesn't need sub-maintainer for system.

Can we cleanup the summary though seems like a different solution is being used now right?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.