Jump to content

PVC – Page-View-Controller


Oliver
 Share

Recommended Posts

Introducing PVC

PvcCore: https://github.com/oliverwehn/PvcCore/

PvcRendererTwig: https://github.com/oliverwehn/PvcRendererTwig/ (coming soon)

PvcGenerator: https://github.com/oliverwehn/PvcGenerator/ (coming soon)

Each time I’ve built a ProcessWire page I’ve struggled with organizing (and separating) code, markup and stuff. Playing around with frameworks (backend as well as frontend) like Rails, Ember and stuff I really liked having a given structure, knowing where to put what piece of code. Therefor I started working on a MVCish way to deal with templates in PW that considers the $page object kind of the data/model layer and adds View and Controller upon it. First by just catching everything via a small processor file added to all PW templates as altFilename. I’ve digged a bit deeper since then and hooked into the native rendering process, have been refactoring my code base more than a dozen times. Now I got a first version that seem to work and I’d love some of you guys to try it out!

PVC (instead of MVC) stands for Page-View-Controller, as it considers PW’s $page var the model/data layer. I’m still working on the README.md on GitHub to document the basics. So have a look for more detailed infos there. I’ll give you a short overview here:

  • Code separation: PVC introduces views and controllers to your PW templates as well as multiple action templates.
  • Controllers, as most of you already know, keep all the business logic. Controllers execute actions wired to routes (urlSegment patterns). Even routes with dynamic segements (e.g. /edit/:id/) can be defined and assigned to an action, providing input through $this->input->route. Values can be set on the controller to be accessable in your templates later on. It’s also possible to set dynamic values as closures to be calculated (e.g. using field values of the current page) on render. Also controllers allow you to set layouts, styles and scripts to be available in your layout or template. Logic can be shared through inheritance between controllers.
  • Views introduce view helpers. Helpers are functions that are made available to you (only) within your template context. There are predefined ones like embed(), snippet(), styles() or scripts(). But you can implement your own helpers easily and share them among your view classes through inheritance.
  • Action templates contain the actual markup. Every action defined in a controller uses its own template. So the same page can display content accordingly to the action that was addressed via urlSegments/route. Within templates you can access all field values and values set on your controller like globals (e.g. <?=$title?>).
  • Modular renderers: PVC implements rendering through separate renderer modules. PvcCore comes with PvcRendererNative that gives you template syntax the good ol’ PW/PHP way. A Twig renderer is in the making. And maybe you want to build your own renderer for the template syntax of your choice?

I consider the module an early Beta version. So make sure to try it within a save environment! Would love to get some feedback (and error reports). I’m no professional developer, so code quality may suck here and there. So I’m glad for inputs on that, too. Also there is some old stuff in there yet, I still have to get rid of. ;)

  • Like 16
Link to comment
Share on other sites

Well, I’ll give you a short example to demonstrate how it all works together. Imagine the following simple setup:

Page Tree

Home
 |- Products (template=products)
 |   |- Product 1 (template=product)
 |   |- Product 2
 |   |- Product 3
 |   |- Product 4
 |   |- Product 5
 |
 |- ...

Page Products with template “products” is meant to show a gallery of product images. So we create a controller for the template (that otherwise would be auto-generated on the fly) in site/templates/controllers/ named products.controller.php.

<?php
/* site/templates/controllers/products.controller.php */
class ProductsController extends BaseController {

  // init() is executed on controller setup before action is called
  public function init() {
    // Just in case you defined general stuff in BaseController’s init() method
    parent::init();

    // Set (for all actions of this controller) a script 'jquery/my.jquery.plugin.js' in group 'footer' with priority 5
    // In layout and template you can then output the scripts group 'footer' using view helper <?=scripts('footer');?>
    // Assets defined via path are looked up in the corresponding folder within site/templates/assets/. You can alternatively
    // define assets using a URL.
    $this->script('jquery/my.jquery.plugin.js', 'footer', 5);

  }

  // index is the default action executed if no other route matches
  public function index() {
    // Add (for this action only) a stylesheet 'gallery.css' to group 'footer' with priority 10.
    // In layout and template you can then output the styles group using view helper <?=styles('footer');?>
    $this->style('gallery.css', 'footer', 10);

    // Set a template var 'products' that contains current page’s children as PageArray
    $this->set('products', $this->page->children('template=product, sort=title'));
  }
}

We’ll need an action template for products’ index action in site/templates/views/products/ named index.tmpl.php.

<!-- site/templates/views/products/index.tmpl.php -->
<h2><?=$title?></h2>

<ul class="products">
<?php foreach($products as $product) { ?>
  <li class="products__item <?=gridClass($product->images->first(), 'products__image');?>"><a href="<?=$product->url?>"><img src="<?=$product->images->first()->url;?>" alt="<?=$product->title;?>"></a></li>
<?php } ?>
</ul>

We’ll have a look at the used view helper gridClass() later.

The first page in PW’s page stack (the one rendered through processPageView directly) is rendered and outputted in a layout’s outletLayouts are stored in site/templates/layouts. There is a default layout default.tmpl.php preinstalled. The rendered action templates are outputted within the document structure by using <?=$outlet?>. You can add as many layouts as you want and change the layout the action template will be rendered in by setting another template within your controller’s init() method like this:

...

public function init() {
  parent::init();

  // use layout site/templates/layouts/shop.tmpl.php for this template
  $this->set('layout', 'shop');
}

... 

Our product template of course also gets a controller:

<?php
/* site/templates/controllers/product.controller.php */

class ProductController extends BaseController {

  public function init() {
    parent::init();   
    // assign route pattern with dynamic segment to action 'reviewVote'
    $this->route('/reviews/:id/vote/', array('id' => '^[0-9]+$'), 'reviewsVote');
  }
  
  public function index() {
    // set dynamic value to be calculated right before rendering the action template
    $this->set('similarProducts', function() {
      // your logic to get a PageArray of similar products goes here
      $tags = $this->page->get('tags'); 
      // or $tags = $this->get('tags'); as it will pass the request through to page, if 'tags' isn’t set on controller itself
      $similarProducts = ...;
      return $similarProducts;
    });
  }

  // action accessible via route /reviews/
  public function reviews() {
    // we should set up this for pagination in template settings
    $this->set('reviews', $this->pages->find("template=reviews, product={$this->page->id}"));
  }

  // action accessible via route /reviews/new/
  public function reviewsNew() {
    // Later versions will allow to handle actions depending on REQUEST_TYPE, but for now:
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
      // create review logic goes here
      ...
      $this->session->redirect(...);
    }
    else {
      $this->set('form', $this->forms->get('review'));
    }
  }

  // action for action route /reviews/:id/vote/
  public function reviewsVote() {
    if($id = $this->input->route->id) {
      // save vote for review
      ...
    }
  }
}

Template product’s action templates go into site/templates/views/product/ named index.tmpl.phpreviews.tmpl.php, etc.

When we talk about routes in PVC, it means patterns of PW’s urlSegments. If you want to have multiple actions and routes, you have to enable urlSegments for the particular template. Index action is performed when a page is addressed directly via its path. If urlSegments are added to the request, PVC captures the urlSegments as a action route and provides it to the controller which determines the action to perform for the route.

Until now all template specific view classes (like ProductsViewProductView) are generated on the fly. Let’s use some view helpers to reduce logic in templates. For example we want pagination looking all the same all over the site. Therefor we define a general view helper for that in site/templates/views/base.view.php.

<?php

class BaseView extends PvcView {

  /**
   * Add custom view helpers that will be available as
   * global functions within your templates.
   * @method customViewHelpers
   * @param Array $scope contains an associative array of template scope
   * @returns Array An associative array with key/closure pairs
   */
  public function customViewHelpers($scope) {
    return array(
      /**
       * Each helper is defined as a pair of key (name of the helper
       * function in template context) and closure (function body)
       * Via use() you can pass in $scope and custom values to be
       * available within your helper.
       * The helper below can be called like this: <?=sayHi('your name');?>
       */
      'pagination' => function(PageArray $pageArray) use($scope) {
        return $pageArray->renderPager(array(
          'nextItemLabel' => "Next",
          'previousItemLabel' => "Prev",
          'separatorItemClass' => "pagination__item--separator",
          'nextItemClass' => "pagination__item--next",
          'previousItemClass' => "pagination__item--prev",
          'currentItemClass' => "pagination__item--current",
          'lastItemClass' => "pagination__item--last",
          'listMarkup' => "<ul class='pagination pagination--{$scope['template']}'>{out}</ul>",
          'itemMarkup' => "<li class='pagination__item {class}'>{out}</li>",
          'linkMarkup' => "<a href='{url}'><span>{out}</span></a>"      
        ));
      })
    );
  }
}

Now you can render your pagination in your action templates just by passing a PageArray value to your pagination view helper like <?=pagination($reviews);?>.

You also can create template-specific view helpers (like gridClass() used in our products action template for index at the top) by creating a view class for the template in site/templates/views/ like this:

<?php
/* site/templates/views/products.view.php */

class ProductsView extends BaseView {

  public function customViewHelpers($scope) {
    $helpers = array(
      'gridClass' => function(PageImage $img, $class=null) {
        $w = $img->width();
        $h = $img->height();
        $orientation = 'square';
        if($w < $h) $orientation = 'portrait';
        if($w > $h) $orientation = 'landscape';
        return is_string($class) ? sprintf('%s--%s', $class, $orientation) : $orientation; 
      }
    );
    return array_merge($helpers, parent::customViewHelpers($scope));
  }
}

Predefined view helpers are for example embed() to render other pages within your current action templatescripts() and styles() to output asset groups and snippet() to render reusable code chunks stored in site/templates/snippets/ within the current action template’s scope.

Hopefully this gives you a vague idea how you can organize your code base using PVC. 

  • Like 10
Link to comment
Share on other sites

@Oliver: When I setup on ProcessWire 2.5.3 as you have mentioned above, I got following error:

Notice: Array to string conversion in C:\xampp\htdocs\pw25\wire\core\PageTraversal.php on line 72

Fatal error: Exception: Field does not exist: Arraysort (in C:\xampp\htdocs\pw25\wire\core\PageFinder.php line 494) #0 [internal function]: PageFinder->___getQuery(Object(Selectors), Array) #1 C:\xampp\htdocs\pw25\wire\core\Wire.php(389): call_user_func_array(Array, Array) #2 C:\xampp\htdocs\pw25\wire\core\Wire.php(344): Wire->runHooks('getQuery', Array) #3 C:\xampp\htdocs\pw25\wire\core\PageFinder.php(263): Wire->__call('getQuery', Array) #4 C:\xampp\htdocs\pw25\wire\core\PageFinder.php(263): PageFinder->getQuery(Object(Selectors), Array) #5 [internal function]: PageFinder->___find(Object(Selectors), Array) #6 C:\xampp\htdocs\pw25\wire\core\Wire.php(389): call_user_func_array(Array, Array) #7 C:\xampp\htdocs\pw25\wire\core\Wire.php(344): Wire->runHooks('find', Array) #8 C:\xampp\htdocs\pw25\wire\core\Pages.php(168): Wire->__call('find', Array) #9 C:\xampp\htdocs\pw25\wire\core\Pages.php(168): PageFinder->find(Object(Selectors), Array) #10 [internal function]: Pages->___find('parent_id=1013,...', Array) #11 C:\xampp\htdo inC:\xampp\htdocs\pw25\index.php on line 226

Error: Exception: Field does not exist: Arraysort (in C:\xampp\htdocs\pw25\wire\core\PageFinder.php line 494)

#0 [internal function]: PageFinder->___getQuery(Object(Selectors), Array)
#1 C:\xampp\htdocs\pw25\wire\core\Wire.php(389): call_user_func_array(Array, Array)
#2 C:\xampp\htdocs\pw25\wire\core\Wire.php(344): Wire->runHooks('getQuery', Array)
#3 C:\xampp\htdocs\pw25\wire\core\PageFinder.php(263): Wire->__call('getQuery', Array)
#4 C:\xampp\htdocs\pw25\wire\core\PageFinder.php(263): PageFinder->getQuery(Object(Selectors), Array)
#5 [internal function]: PageFinder->___find(Object(Selectors), Array)
#6 C:\xampp\htdocs\pw25\wire\core\Wire.php(389): call_user_func_array(Array, Array)
#7 C:\xampp\htdocs\pw25\wire\core\Wire.php(344): Wire->runHooks('find', Array)
#8 C:\xampp\htdocs\pw25\wire\core\Pages.php(168): Wire->__call('find', Array)
#9 C:\xampp\htdocs\pw25\wire\core\Pages.php(168): PageFinder->find(Object(Selectors), Array)
#10 [internal function]: Pages->___find('parent_id=1013,...', Array)
#11 C:\xampp\htdo
This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged.
Link to comment
Share on other sites

I have installed and then setup controllers and views as per your post. I then created same pages with template that you have in you screenshot.

I have also corrected your code which was giving me error as follows:

public method function init()

parent::init(); (here one colon was missing)

Removed ... part.

I really like that I can use MVCish style in PW so if it works then I am all for it.

Link to comment
Share on other sites

@fmgujju: I guess I solved it. It was a minor error when passing method calls through my PvcPageProxy class. Grab the latest version from github and give it another try. Thanks for testing. There has been another error in my examples above: In products’ action template for index you have to add ->url at the end of the PW API call within the src attribute of the img tag to make it show the images.

  • Like 1
Link to comment
Share on other sites

Thanks Oliver for sharing, just I can't really try it out for various reasons.

I'm really digging people share their "MVC" approaches, but with this one more, it would be around 5 different ones now around. I'm not sure what to think about the impact on PW new and old users, support etc as it will split and create burdens for one to help someone using x-mvc approach. I have nothing against many ways to setup PW projects and while that's a strength it may even more is a weakness at the same time with its consequences. 

Really not against you and your approach, it just turns out by chance that I write this here. I'm not sure its worth of discussion.

Wouldn't it be better to settle on one "MVC" ish setup that PW maybe even supports, it could help to keep focus on it and maybe even have official docs for it. Often it doesn't help telling a dev hey look there's this this and this but you can also use this and this, but that is not for PW 2.5 while that is only for php 5.5 and the other you can't use if you use multisite and those are not multilanguageable. Hard for me to explain well but I think one get the idea where I'm heading.

  • Like 3
Link to comment
Share on other sites

I absolutely get your point, Soma. I’ve always been a trial-and-error kind of coder, so I tried a lot, built a lot of stuff the way I thought was right. I hated how bad my code was structured and how hard it was to maintain. So I experimented with ways to separate things, tried approaches like your “delegate” one but didn’t really arrive at a point of happiness.

As I said I have been experimenting with other languages and frameworks like Ember, Rails etc. and I really fell in love with the burden of defining a meaningful and comprehensible structure being taken off me. Of course, the thing that brought me to PW was its freedom. But for me as a designer it was especially the freedom of how to build templates (as data containers) and how to present them easiy with PWs API at hand in your template files. But as soon as you want your PW site to do more than render web pages it (at least in my semi-semi-pro-dev experience) gets messy pretty fast when you try to wire things up to make a page do more than one thing.

So I really think it’s justifiable to use PWs modular base to build a MVCish layer upon it. Especially when you think of the fact that native page rendering has been a module itself from the start. Of course it’s not ideal to have a dozen of concepts around. I’ve kept an eye on earlier modules/concepts going in a similar direction but they mostly just dealt with a certain part of my issue. So I started experimenting (again) to create kind of a proof of concept and I wanted to share this with the community. 

If there is a real MVCish approach that is/will be supported by PW Core Team I’d be more than happy to support it. Did I miss something here?

standards.png

  • Like 5
Link to comment
Share on other sites

@fmgujju: I guess I solved it. It was a minor error when passing method calls through my PvcPageProxy class. Grab the latest version from github and give it another try. Thanks for testing. There has been another error in my examples above: In products’ action template for index you have to add ->url at the end of the PW API call within the src attribute of the img tag to make it show the images.

Thanks Oliver! It's working now after grabbing your latest code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Robin S
      Repeater Easy Sort
      Adds a compact "easy-sort" mode to Repeater and Repeater Matrix, making those fields easier to sort when there are a large number of items.
      The module also enhances Repeater Matrix by allowing a colour to be set for each matrix type. This colour is used in the item headers and in the "add new" links, to help visually distinguish different matrix types in the inputfield.
      Screencasts
      A Repeater field

      A Repeater Matrix field with custom header colours

      Easy-sort mode
      Each Repeater/Matrix item gets an double-arrow icon in the item header. Click this icon to enter easy-sort mode.
      While in easy-sort mode:
      The items will reduce in width so that more items can be shown on the screen at once. The minimum width is configurable in the field settings. Any items that were in an open state are collapsed, but when you exit easy-sort mode the previously open items will be reopened. You can drag an item left/right/up/down to sort it within the items. The item that you clicked the icon for is shown with a black background. This makes it easier to find the item you want to move in easy-sort mode. You can click an item header to open the item. An "Exit easy-sort mode" button appears at the bottom of the inputfield. Configuration
      In the field settings for Repeater and Repeater Matrix fields you can define a minimum width in pixels for items in easy-sort mode. While in easy-sort mode the items will be sized to neatly fill the available width on any screen size but will never be narrower than the width you set here.
      In the field settings for Repeater Matrix you can define a custom header colour for each matrix type using an HTML "color" type input. The default colour for this type of input is black, so when black is selected in the input it means that no custom colour will be applied to the header.
      Exclusions
      The easy-sort mode is only possible on Repeater/Matrix fields that do not use the "item depth" option.
       
      https://github.com/Toutouwai/RepeaterEasySort
      https://processwire.com/modules/repeater-easy-sort/
    • By FireWire
      Hello community!

      I want to share a new module I've been working on that I think could be a big boost for multi-language ProcessWire sites.

      Some background, I was looking for a way for our company website to be efficiently translated as working with human translators was pretty laborious and a lack of updating content created a divergence between languages. I, and several other devs here, have talked about translation integrations and have recognized the power that DeepL has. DeepL is an AI deep learning powered service that delivers translation quality beyond any automated service available. After access to the API was opened up to the US, I built Fluency, a DeepL translation integration for ProcessWire.
      Fluency brings automated translation to every multi-language field in the admin, and also provides a translation tool allowing the user to translate their text to any language without it being inside a template's field. With Fluency you can:
      Translate any plain textarea or text input Translate any CKEditor content (yes, with markup) Translate page names for fully localized URLs on every page Translate your in-template translation function wrapped strings Translate modules Fluency is free, and now so is DeepL
      Since this module was first built DeepL has introduced free Developer accounts that allow anyone to start using Fluency at zero cost and beginning with the version 0.3.0 release Fluency now supports free DeepL accounts. As of June 2021 DeepL supports translation to 26 languages and continues to offer more.
      Installation and usage is completely plug and play. Whether you're building a new multi-language site, need to update a site to multi-language, or simply want to stop manually translating a site and make any language a one-click deal, it could not be easier to do it. Fluency works by having you match the languages configured in ProcessWire to DeepL's. You can have your site translating to any or all of the languages DeepL translates to in minutes (quite literally).
      Let's break out the screenshots...
      When the default language tab is shown, a message is displayed to let users know that translation is available. Clicking on each tab shows a link that says "Translate from English". Clicking it shows an animated overlay with the word "Translating..." cycling through each language and a light gradient shift. Have a CKEditor field? All good. Fluency will translated it and use DeepL's ability to translate text within HTML tags. CKEditor fields can be translated as easily and accurately as text/textarea fields.

      Repeaters and AJAX created fields also have translation enabled thanks to a JavaScript MutationObserver that searches for multi-language fields and adds translation as they're inserted into the DOM. If there's a multi-language field on the page, it will have translation added.

      Same goes for image description fields. Multi-language SEO friendly images are good to go.

      Creating a new page from one of your templates? Translate your title, and also translate your page name for native language URLs. (Not available for Russian, Chinese, or Japanese languages due to URL limitations). These can be changed in the "Settings" tab for any page as well so whether you're translating new pages or existing pages, you control the URLs everywhere.

      Language configuration pages are no different. Translate the names of your languages and search for both Site Translation Files (including all of your modules)

      Translate all of the static text in your templates as well. Notice that the placeholders are retained. DeepL is pretty good at recognizing and keeping non-translatable strings like that. If it is changed, it's easy to fix manually.

      Fluency adds a "Translate" item to the CMS header. When clicked this opens up a modal with a full translation tool that lets the user translate any language to any language. No need to leave the admin if you need to translate content from a secondary language back to the default ProcessWire language. There is also a button to get the current API usage statistics. DeepL account owners can set billing limitations via character count to control costs. This may help larger sites or sites being retrofitted keep an eye on their usage. Fluency can be used by users having roles given the fluency-translate permission.

      It couldn't be easier to add Fluency to your new or existing website. Simply add your API key and you're shown what languages are currently available for translation from/to as provided by DeepL. This list and all configuration options are taken live from the API so when DeepL releases new languages you can add them to your site without any work. No module updates, just an easy configuration. Just match the language you configured in ProcessWire to the DeepL language you want it to be associated with and you're done. Fluency also allows you to create a list of words/phrases that will not be translated which can prevent items such as brands and company names from being translated when they shouldn't

       
      Limitations:
      No "translate page" - Translating multiple fields can be done by clicking multiple translation links on multiple fields at once but engineering a "one click page translate" is not feasible from a user experience standpoint. The time it takes to translate one field can be a second or two, but cumulatively that may take much longer (CKEditor fields are slower than plain text fields). There may be a workaround in the future but it isn't currently on the roadmap. See a solution below... No "translate site" - Same thing goes for translating an entire website at once. It would be great, but it would be a very intense process and take a very (very) long time. There may be a workaround in the future but it isn't on the roadmap. No current support for Inline CKEditor fields - Handling for CKEditor on-demand hasn't been implemented yet, this is planned for a future release though and can be done. I just forgot about it because I've never really used that feature personally.. Alpha release - This module is in alpha. Releases should be stable and usable, but there may be edge case issues. Test the module thoroughly and please report any bugs via a Github issue on the repository or respond here. Please note that the browser plugin for Grammarly conflicts with Fluency (as it does with many web applications). To address this issue it is recommended that you disable Grammarly when using Fluency, or open the admin to edit pages in a private window where Grammarly may not be loaded. This is a long-standing issue in the larger web development community and creating a workaround may not be possible. If you have insight as to how this may be solved please visit the Github page and file a bugfix ticket.
      Enhancements
      Translate All Fields On A Page
      An exciting companion module has been written by @robert which extends the functionality of Fluency to translate all fields on a page at once. The module has several useful features that can make Fluency even more useful and can come in handy for translating existing content more quickly. I recommend reading his comments for details on how it works and input on best practices later in this thread.
      Get the module at the Github repo: https://github.com/robertweiss/ProcessTranslatePage
      Requirements:
      ProcessWire  3.0+ UIKit Admin Theme That's Fluency in a nutshell. A core effort in this module is to create it so that there is nothing DeepL related hard-coded in that would require updating it when DeepL offers new languages. I would like this to be a future-friendly module that doesn't require developer work to keep it up-to-date.
      The Module Is Free
      This is my first real module and I want to give it back to the community as thanks. This is the best CMS I've worked with (thank you Ryan & contributors) and a great community (thank you dear reader).
      DeepL Developer Accounts
      In addition to paid Pro Developer accounts, DeepL now offers no-cost free accounts. Now all ProcessWire developers and users can use Fluency at no cost. Learn more about free and paid accounts by visiting the DeepL website. Sign up for a Developer account, get an API key, and start using Fluency.
      Download & Feedback
      Download the latest version here
      https://github.com/SkyLundy/Fluency-Translation/archive/main.zip
      Github repository:
      https://github.com/SkyLundy/Fluency-Translation
      File issues and feature requests here (your feedback and testing is greatly appreciated):
      https://github.com/SkyLundy/Fluency-Translation/issues
       
      Thank you! ¡Gracias! Ich danke Ihnen! Merci! Obrigado! Grazie! Dank u wel! Dziękuję! Спасибо! ありがとうございます! 谢谢你!

    • By kixe
      Field that stores one or more references to ProcessWire pages with additional data in field context.
      Values are editable via page edit modal of the referenced page provided from the field if module AdminPageFieldEditLinks is installed and "Enable link to create new pages?" is checked in field settings.
      Requirements: AdminPageFieldEditLinks >= 3.1.4
      https://github.com/kixe/FieldtypePageContextData
      https://processwire.com/modules/fieldtype-page-context-data/
      Use case example:
      The planning of the Tonmeistertagung in the CCD (Congress Center Düsseldorf) from November 3rd, 2021 to November 6th, 2021 is in the finalization phase.
      The conference consists of a conference part and an exhibition. The planning is done via a separate frontendless PW instance. There, all companies (pages) that are active at various events are kept in a pool. Changes (address, logo) can always be done there. For the exhibition of the current conference in November, the exhibitor-companies (pages) are selected via a page reference field. A stand number must now be assigned to each selected company (page). We had originally solved this using the Profield FieldtypeTable. However, this had the disadvantage that each entry again made all companies available for selection and did not recognize which were already selected in a previous table row. The new field type now allows the value (company's stand number) to be assigned to a Company (page) in context to a specific Pagefield living in a specific page.
      https://tonmeistertagung.com/en/exhibitors/exhibition/
       
    • By Robin S
      This module lets you add some custom menu items to the main admin menu, and you can set the dropdown links dynamically in a hook if needed.
      Sidenote: the module config uses some repeatable/sortable rows for the child link settings, similar to the ProFields Table interface. The data gets saved as JSON in a hidden textarea field. Might be interesting to other module developers?
      Custom Admin Menus
      Adds up to three custom menu items with optional dropdowns to the main admin menu.
      The menu items can link to admin pages, front-end pages, or pages on external websites.
      The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon.
      Requires ProcessWire v3.0.178 or newer.
      Screenshots
      Example of menu items

      Module config for the menus

      Link list shown when parent menu item is not given a URL

      Advanced
      Setting child menu items dynamically
      If needed you can set the child menu items dynamically using a hook.
      Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']); $children = []; foreach($colours as $colour) { // Each child item should be an array with the following keys $children[] = [ 'icon' => $colour['page_icon'], 'label' => $colour['title'], 'url' => $colour['url'], 'newtab' => false, ]; } $event->return = $children; } }); Create multiple levels of flyout menus
      It's also possible to create multiple levels of flyout submenus using a hook.

      For each level a submenu can be defined in a "children" item. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $children = [ [ 'icon' => 'adjust', 'label' => 'One', 'url' => '/one/', 'newtab' => false, ], [ 'icon' => 'anchor', 'label' => 'Two', 'url' => '/two/', 'newtab' => false, 'children' => [ [ 'icon' => 'child', 'label' => 'Red', 'url' => '/red/', 'newtab' => false, ], [ 'icon' => 'bullhorn', 'label' => 'Green', 'url' => '/green/', 'newtab' => false, 'children' => [ [ 'icon' => 'wifi', 'label' => 'Small', 'url' => '/small/', 'newtab' => true, ], [ 'icon' => 'codepen', 'label' => 'Medium', 'url' => '/medium/', 'newtab' => false, ], [ 'icon' => 'cogs', 'label' => 'Large', 'url' => '/large/', 'newtab' => false, ], ] ], [ 'icon' => 'futbol-o', 'label' => 'Blue', 'url' => '/blue/', 'newtab' => true, ], ] ], [ 'icon' => 'hand-o-left', 'label' => 'Three', 'url' => '/three/', 'newtab' => false, ], ]; $event->return = $children; } }); Showing/hiding menus according to user role
      You can determine which menu items can be seen by a role by checking the user's role in the hook.
      For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); $user = $event->wire()->user; // For custom menu number 1... if($menu_number === 1) { // ...if user does not have some particular role... if(!$user->hasRole('foo')) { // ...do not show the menu $event->return = false; } } });  
      https://github.com/Toutouwai/CustomAdminMenus
      https://processwire.com/modules/custom-admin-menus/
    • By tcnet
      This module for ProcessWire sends a notification email for each failed login attempt. Similar modules exists already in the module directory of ProcessWire. However, this module is designed to notify, even if specified user doesn't exist.
      Settings
      The settings for this module are located in the menu Modules=>Configure=>LoginFailNotifier.
      Notification email
      Specifies the email address to which the notification emails should be sent.
        Email subject
      Specifies the subject line for the notification email.
        Post variables
      Specifies the $_POST variables to be included in the notification email. Each variable must be separated by a comma. For example: login_name,login_pass
        Server variables
      Specifies the $_SERVER variables to be included in the notification email. Each variable must be separated by a comma. For example: REMOTE_ADDR,HTTP_USER_AGENT
      Link to ProcessWire module directory:
      https://processwire.com/modules/login-fail-notifier/
      Link to github.com:
      https://github.com/techcnet/LoginFailNotifier
×
×
  • Create New...