Joomla Google Summer of Code 2019

This blog highlights the development process involved in building the next 3 tasks of my GSoC project.

These include:

  1. Improve the incorporation of Modules in Articles
  2. Integrate Workflows in Modules Component
  3. Merge Featured Model into Articles

Improve the incorporation of Modules in Articles

PR Link: https://github.com/joomla/joomla-cms/pull/34764

This task has 2 parts:

  1. Create Modules in Article Edit View
  2. Imported Modules Tab

Create Modules in Article Edit View

Users can add Modules in Articles in Joomla. This is done with the help of the Module xtd-editor Plugin. However, this Plugin opens a Modal that only allows the user to select a pre-existing module. there is no option to add a new module directly in the Article Edit View. To enhance that, this PR introduces a button to Create Modules directly in the Article Edit View:

You can view a video demo of the above here: https://youtu.be/68JgXZcuPJI

This is implemented using a cookie which can be read and modified by both PHP (to not display the Save and Close button in Toolbar for unsaved modules) and JavaScript (to clear this flag when we close the modal). Hiding Save and Close button is necessary here because we need to make sure that the module is saved (in our database) before we close the modal so we can grab the module's ID.

This task has been implemented by re-using the existing controller functions by modifying them just enough to support backward compatibility.

Imported Modules Tab

This tab allows us to perform Edit and Remove operations on the imported module using buttons. It displays Modules that are imported using any of the 3 possible syntaxes (supports older import syntaxes for backwards compatibility):

  1. {loadmodules :mod_type}

These are matched using regular expressions where we find the expressions that match either of these above configurations. Using the matched indexes, we filter the id / mod_type or position and we use that it in further queries to obtain more information about these modules from the database.

This additional information is then displayed in the form of a table where users can interact with the Edit and Delete button to modify these modules.

Picture1

Integrate Workflows in Modules Component

PR Link: https://github.com/joomla/joomla-cms/pull/35101

This is an additional feature enhancement that was not in the primary project description. Workflow has been only used in `com_content`, ie. the Articles Component until now. In this task, we see how it can be integrated into other components. For the purpose of this task, we have chosen `com_modules`, ie. Modules as our Component.

Access

The corresponding access.xml actions have been added.

Articles Model

The getListQuery() method joins the old query with workflow_associations to also consider the workflow stages that belong to com_content.articles only.

SQL Changes:

  • The following have been added to the Database Tables:
    • 1 new workflow: `COM_WORKFLOW_BASIC_WORKFLOW_MODULES`
    • 1 new stage: `COM_WORKFLOW_BASIC_STAGE`
    • 3 new transitions:
  • Publish
  • Unpublish
  • Trash
    • Workflow Associations have been created for all existing modules via an update script / a query during Installation.

Introduce a new Backend Menu Item

A new menu page item in the sidebar for Modules: Workflows to execute CRUD for com_modules

Option to Enable Workflow Integration

This can be toggled from Global Configuration. It controls whether workflows are enabled or not

Searchtools Filtering

Added a new option to filter modules via their workflow stage.

ModulesComponent.php

Added necessary functions that are used by Workflow Plugins (Workflows, Featuring and Publishing)

Module Model

  • The get query now takes into account the workflow stage associated with each module.
  • Added Workflow before and after Save events
  • Added a function to get the initial stage for a module (default workflow and default stage)
  • Added a query to create workflow association while duplicating modules
  • Added a function that prepares the workflow field

Modules Model

This project adds a filterForm function to filter based on the workflow stage. This query also joins the module table with workflow associations.

Workflow associations comprise a table that associates every element under a certain extension with its active workflow stage. This table allows us to easily find relations between modules and their workflow stages.

Modules Template:

  • Added workflows column to the table
  • This column is conditionally rendered when workflows are enabled
  • Added workflows field to default batch body

The Flow:

When creating new modules you have to select a workflow and when you save, the default stage under this workflow_id is set as the initial stage of the module. When editing existing modules, the workflow transition field is shown instead of the workflow_id field, which works similarly to com_content.

New Modules: Select Workflow

Similar to workflow assignment for com_content where we linked it to a category to initialize its workflow. We can select the workflow associated with it upon creation.

Picture2

Edit Existing Modules: Transition Field

This field is only shown for modules that have already been created. Here instead of selecting the workflow associated, we can execute transitions.

Picture3

Merge Featured Articles into Articles

PR Link: https://github.com/joomla/joomla-cms/pull/35228

The primary aim for this task was to refactor the code in order to enhance the code re-usability and eliminate redundancy. It eliminates redundancy by merging the different files that were made for the Model, View, Controller and Template of the featured articles and all articles into a common MVC.

[A] New Selector Dropdown

A searchtools selector is added that can be used to toggle between:

Option  Value 
 All  """
 Unfeatured  0
 Featured  1

 

Picture4

[B] Model Merged

A new method to return the featured selector filter parameter using the getUserState from request

$featured = $this->getUserStateFromRequest($this->context . '.featured', 'featured', '');

The advantage of the above is that we can also pass the value as a GET param to the URL which helps us to make redirect URLs that can initialize the value of this dropdown

$featured variable is used as a condition to manipulate the query to adjust to Featured

[C] Templates Merged

We use state->get('featured') to conditionally render the template code as per featured or not.

[D] Views Merged

We use state->get('featured') to conditionally render the toolbar options.

[E] Controller Merged

Merged the delete function from FeaturedController

Modules Position Badge

This was a bonus task. The aim here was to visually indicate the positions that aren't a part of any of the active template styles. This could help the users understand if there was any position that is valid but not active.

getValidPositions()

Added a new model method getValidPositions that performs the following:

1. Fetch the active template from the database (1 Query)

Picture5

2. Get the templateDetails.xml file corresponding to the template received as a result of Step 1

3. Store these positions in an array and return it

  1. Store these positions in an array and return it

The array returned from the above model method will be used in the _getList function as:

  1. Stored the result of the getValidPositions method in an array
  2. After fetching all modules from the database for rendering, perform a check whether each module row's position exists in the array of step 1 If yes, set $row->activePosition to true If no, set $row->activePosition to false

Finally, in the tmpl file, we use this activePosition flag to conditionally select between bg-primary and bg-secondary. Badges for In-active (not of the active template) Positions have a bg-secondary class.

Picture6

Mentors

My mentors have been an integral part of my journey. It was their constant guidance that helped me complete all my tasks successfully and submit robust code. Thank you:

  1. Christiane Maier-Stadtherr
  2. Niels Braczek
  3. Benjamin Trenkle
  4. Achilleas Papageorgiou
  5. Luca Marzo

Special Thanks to Richard Fath And my fellow Joomla GSoC Student Developers: Kumar Shivam, Rishabh Ranjan Jha, Rahul Saini and Eyvaz Ahmadzada.

Future Roadmap

Although the first iteration of all the tasks has been completed and is in a functional stage, there is always scope for improvement. I plan to continue being involved with Joomla. I will push regular commits as and when more reviews and suggestions drop in. I also plan to extend my involvement in other possible ways, including contributing to the main repo, fixing bugs, reviewing PRs and helping new contributors learn through the codebase.