Problem/Motivation

I would like to opt into to security coverage for the Commerce Ajax ATC (Add to cart) module.

The description from the module's project page describes the ways that this ajax module is distinct from the other ajax modules: The Commerce Ajax ATC (Add to cart) module provides a flexible way to add ajax functionality to the Drupal Commerce add to cart form. It provides a variety of ways to render the pop-up messages that can be configured through the UI.

The Commerce Ajax ATC (Add to cart) module differs from the other ajax add to cart modules in the following ways:

  1. The Commerce Ajax ATC (Add to cart) module targets add to cart forms specifically by their ID, so there is complete control over which add to cart forms use ajax.
  2. You enable ajax on the add to cart form through third party settings the same way the Combine order items containing the same product variation. setting is used. This means you can use ajax on one view mode display, and not use it on another display.
  3. We also swap all of the default commerce add to cart messages that implement ajax as described in this article, and as is done in the Commerce Ajax Cart Message module. This allows us to build and control our own custom messages.
  4. The messages that the Commerce Ajax ATC (Add to cart) module provides are configurable through the UI.
  5. Commerce Ajax ATC (Add to cart) module offers 3 types of add to cart confirmation messages.
    1. A configurable non-modal message above the add to cart form.
    2. A configurable modal message pop up.
    3. A configurable colorbox message pop up (requires Colorbox Load module).
  6. You can render the pop-up messages through a twig template, and render the product variation in a view mode.

Project link

https://www.drupal.org/project/commerce_ajax_atc

Git instructions

git clone --branch '1.0.x' https://git.drupalcode.org/project/commerce_ajax_atc.git

Comments

tonytheferg created an issue. See original summary.

tonytheferg’s picture

Title: D9 Commerce Ajax ATC » [D9] Commerce Ajax ATC
Issue summary: View changes
avpaderno’s picture

Issue summary: View changes
rajeshreeputra’s picture

At multiple places called t() function in .module file, which need to be fixed.
t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead

avpaderno’s picture

Status: Needs review » Needs work
tonytheferg’s picture

It's not in a class, It's in a module file. Do you have an example of a module file that implements $this->t() ?

tonytheferg’s picture

Status: Needs work » Needs review

Views does the exact same thing in their module file:

/**
 * Implements hook_help().
 */
function views_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.views':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Views module provides a back end to fetch information from content, user accounts, taxonomy terms, and other entities from the database and present it to the user as a grid, HTML list, table, unformatted list, etc. The resulting displays are known generally as <em>views</em>.') . '</p>';
      $output .= '<p>' . t('For more information, see the <a href=":views">online documentation for the Views module</a>.', [':views' => 'https://www.drupal.org/documentation/modules/views']) . '</p>';
      $output .= '<p>' . t('In order to create and modify your own views using the administration and configuration user interface, you will need to enable either the Views UI module in core or a contributed module that provides a user interface for Views. See the <a href=":views-ui">Views UI module help page</a> for more information.', [':views-ui' => (\Drupal::moduleHandler()->moduleExists('views_ui')) ? Url::fromRoute('help.page', ['name' => 'views_ui'])->toString() : '#']) . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Adding functionality to administrative pages') . '</dt>';
      $output .= '<dd>' . t('The Views module adds functionality to some core administration pages. For example, <em>admin/content</em> uses Views to filter and sort content. With Views uninstalled, <em>admin/content</em> is more limited.') . '</dd>';
      $output .= '<dt>' . t('Expanding Views functionality') . '</dt>';
      $output .= '<dd>' . t('Contributed projects that support the Views module can be found in the <a href=":node">online documentation for Views-related contributed modules</a>.', [':node' => 'https://www.drupal.org/documentation/modules/views/add-ons']) . '</dd>';
      $output .= '<dt>' . t('Improving table accessibility') . '</dt>';
      $output .= '<dd>' . t('Views tables include semantic markup to improve accessibility. Data cells are automatically associated with header cells through id and header attributes. To improve the accessibility of your tables you can add descriptive elements within the Views table settings. The <em>caption</em> element can introduce context for a table, making it easier to understand. The <em>summary</em> element can provide an overview of how the data has been organized and how to navigate the table. Both the caption and summary are visible by default and also implemented according to HTML5 guidelines.') . '</dd>';
      $output .= '<dt>' . t('Working with multilingual views') . '</dt>';
      $output .= '<dd>' . t('If your site has multiple languages and translated entities, each result row in a view will contain one translation of each involved entity (a view can involve multiple entities if it uses relationships). You can use a filter to restrict your view to one language: without filtering, if an entity has three translations it will add three rows to the results; if you filter by language, at most one result will appear (it could be zero if that particular entity does not have a translation matching your language filter choice). If a view uses relationships, each entity in the relationship needs to be filtered separately. You can filter a view to a fixed language choice, such as English or Spanish, or to the language selected by the page the view is displayed on (the language that is selected for the page by the language detection settings either for Content or User interface).') . '</dd>';
      $output .= '<dd>' . t('Because each result row contains a specific translation of each entity, field-level filters are also relative to these entity translations. For example, if your view has a filter that specifies that the entity title should contain a particular English word, you will presumably filter out all rows containing Chinese translations, since they will not contain the English word. If your view also has a second filter specifying that the title should contain a particular Chinese word, and if you are using "And" logic for filtering, you will presumably end up with no results in the view, because there are probably not any entity translations containing both the English and Chinese words in the title.') . '</dd>';
      $output .= '<dd>' . t('Independent of filtering, you can choose the display language (the language used to display the entities and their fields) via a setting on the display. Your language choices are the same as the filter language choices, with an additional choice of "Content language of view row" and "Original language of content in view row", which means to display each entity in the result row using the language that entity has or in which it was originally created. In theory, this would give you the flexibility to filter to French translations, for instance, and then display the results in Spanish. The more usual choices would be to use the same language choices for the display language and each entity filter in the view, or to use the Row language setting for the display.') . '</dd>';
      $output .= '</dl>';
      return $output;
  }
}
avpaderno’s picture

Drupal core is still calling t() in procedural code, as functions cannot use StringTranslationTrait.

I apologize: I misread the comment #4 and thought it was referring to a file used by the module, not to the .module itself. That's why I changed status.

tonytheferg’s picture

Yup, no problem. I did however use it everywhere else. (the settings form, etc.)

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Fixed

Thank you for your contribution! I am going to update your account.

These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.