The main issue with this module is still the migration to using entities.. this is indirectly a step in the right direction...

Much of the entity refactoring will unpick the tangle that is template_preprocess_simplereservation_week()
There is a no separation of concerns with lots of database queries mixed in with the preparation of prev/next links for the header/banner

Only entity logic will remain in the processing function ( for removal into entities as the next step)

I have broken the template rendering into two.

1) simplereservation-week-header.html.twig
2) simplereservation-week-html-twig

The first, the template for the prev/next links and displays the month on the week number correctly.
The bottom template the reservations.

This has one advantage, the header can be common to many users, as its only inputs are year and week number ( 1..52 )
and can be cached separately

I have simplified the formatting of the prev/next link by passing as a variable a DateTime Object for what was prev_4week etc
and now at the last moment the template takes care of the string conversion
see \Drupal\simplereservation\Controller\ReservationController::calc_prev_next_links()

I will post what I have in the next few days.

Comments

martin107’s picture

Issue summary: View changes
StatusFileSize
new11.49 KB

First iteration.

martin107’s picture

StatusFileSize
new13.8 KB
new3.82 KB

restored functionality when to display text "There are no items for reservation" by moving some logic in preprocess into the controller

default value of imgpath can be set and then forgotten about. reducing the preprocess function

martin107’s picture

StatusFileSize
new17.32 KB
new5.53 KB

first action in simplereservation-week.html.twig was an access check!

if accessGranted

An inappropiate conditional check within a template file. In addition this was a needless duplicate of the existing check in the simplereservation.routing.yml file

martin107’s picture

StatusFileSize
new1.26 KB
new17.31 KB

date rate in reservation list now matches date range from banner.

martin107’s picture

StatusFileSize
new20.03 KB
new6.63 KB

Many minor changes to preprocess function.

Putting sql related statements together.
There is no need to produce week_day array when the day ( Mon, Tue etc ) can be got from format call on the calendar[].
config array just contains a calendar array so removed config wrapper.
$day was being used as a dateTime object and a loop index, now using i for loop index.

martin107’s picture

Status: Active » Fixed

  • martin107 committed ccc3f04 on 8.x-1.x-dev
    #2335821 Refactor template_preprocess_simplereservation_week
    

Status: Fixed » Closed (fixed)

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

martin107’s picture

Assigned: martin107 » Unassigned