Jump to content
adrian

Email New User

Recommended Posts

@adrian Sending copies to a list of users would certainly come in very handy! For debugging user registration scripts, I'd usually have to switch Bcc recipients regularly.

As for re-branding the Bcc option as "notify other users": sounds good, too. I'm fine with the way it works now and would see the ability to send multiple copies as a priority, but I certainly see your point in simplifying it.

  • Like 1

Share this post


Link to post
Share on other sites
20 hours ago, d'Hinnisdaël said:

@adrian Sending copies to a list of users would certainly come in very handy! For debugging user registration scripts, I'd usually have to switch Bcc recipients regularly.

As for re-branding the Bcc option as "notify other users": sounds good, too. I'm fine with the way it works now and would see the ability to send multiple copies as a priority, but I certainly see your point in simplifying it.

Ok, It now supports a comma-separated list of email addresses and it has been rebranded as "Notify Other Users" and it now uses "To" for sending to these addresses as well.

Please let me know if you see any problems.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @adrian thanks for this great module.

I want to always show the "Send welcome message" field/checkbox for new users, that I create in the admin.
But this checkbox never shows. I filled out the email-address but it still does not show up.
I unchecked the option "Automatic Email Send" in the modules settings, because I want to choose if a user should get a welcome email or not.

Could this be because of the core version of PW that I am using? I am using 3.0.71 right now.

I turned on ProcessWire debug now, and EmailNewUser triggers an error:

Trying to get property of non-object in K:\xampp\htdocs\myproject\src\site\assets\cache\FileCompiler\site\modules\EmailNewUser\EmailNewUser.module on line 54

That line reads 

if ($this->wire('page')->process == "ProcessUser") $this->addHookAfter('ProcessPageEdit::buildFormContent', $this, 'addEmailFields');

I think the problem is 

$this->wire('page')->process == "ProcessUser"

but I am not sure. Any suggestions?

emailnewuser.png

  • Like 1

Share this post


Link to post
Share on other sites

Hi @jmartsch - glad you are finding it useful. 

I can't seem to reproduce any of the problems you are having

What version of the module are you running? Line #54 isn't that line in the current version, although it's only one off, so maybe it's a misreporting?

Do the various fields show when you have the automatic option check in the module config settings?

Also, what is it that you are dumping on line 72 that is returning "FieldtypePassword" ?

One thing to try here - can you change the:

public function init() {

on line 48 to:

public function init() {

}

public function ready() {

Yes, it is making the init function empty and converting the current init() function into a ready() function.

Please let  me know if that helps.

  • Like 1

Share this post


Link to post
Share on other sites

Hey @adrian. Thanks for your quick reply :)

42 minutes ago, adrian said:

Do the various fields show when you have the automatic option check in the module config settings?

 

No they did not show even when the option was checked.

Switching the init function to a ready function fixes the problem. I also thought of doing this, but didn't do it.
Now it is working fine :)

42 minutes ago, adrian said:

What version of the module are you running? Line #54 isn't that line in the current version, although it's only one off, so maybe it's a misreporting?

 

I use the latest version from github = 1.0.5 and if I open the file in a texteditor or in my IDE then line 54 is the correct line.

EDIT: Weird, on github it is line 55. Must be something in my editors.

Regarding the output of line 72 (that was something that I added):

bd($event->object->attributes["class"]);

There is a problem with removing the required attribute from password fields. It gets removed, but if you accidentally enter something in the password field and then delete it, you can not submit the form, because the required attribute gets added back in. This is coming from the InputfieldPassword.js which gets added to the page. Starting in line 120 it reads

$input.on('change', function() {
			var val = $(this).val();
			if(val.length > 0) {
				$input.attr('required', 'required');	
				$confirm.attr('required', 'required');
			} else if(!$(this).closest('.InputfieldStateRequired').length) {
				$input.removeAttr('required');
				$confirm.removeAttr('required');
			}
		});

So if the "Generate Password" Option is set, the script should not be executed or loaded.

One approach would be, to remove the CSS class "InputfieldPasswordComplexify" so the script does not react to it.

I tried to make a hook for this, but it does not work yet. Maybe you have some suggestions?

Here is my hook in the ready function:

$this->addHookBefore('InputfieldPassword::render', $this, 'removeComplexify');

and here the function

 protected function removeComplexify(HookEvent $event)
    {
        $f = $event->object;
        bd($f);
        $f->removeClass('InputfieldPasswordComplexify');
    }

I don't know what is wrong or if this is the right approach. I even tried to use addHookAfter, which also did not work. 

Maybe you have an idea?!

  • Like 2

Share this post


Link to post
Share on other sites

Wow, thanks for noticing that issue when manually entering and deleting a password - I had never come across that before.

The reason that "before" hook doesn't work for is because the InputfieldPassword::render() method uses addClass('InputfieldPasswordComplexify'), so you are removing it before it's actually added. I have achieved the same thing though with a str_replace on an "after" hook - not as elegant, but works fine.

You actually got me thinking about the whole approach to automatically generating the password and I thought it might be better to actually populate the fields when creating the user, rather than leaving them blank and populating when publishing the user.

I am going to PM you my current dev version to take a look at as see what you think of this new approach.

Thanks again for your help/feedback with this!

  • Like 1

Share this post


Link to post
Share on other sites

Ok, I have committed a new version which fixes the two bugs that @jmartsch reported.

As mentioned above, I have also revamped the password generator - it now populates the password fields while you are creating the user and the generated password matches the options defined in the PW "pass" field's config settings. The only one I can't match is the complexity factor, but so long as you stick to the default (or lower) it should all be fine - thanks to @Robin S's Password Generator (https://processwire.com/talk/topic/17406-password-generator/) for some inspiration :) 

Please let me know if you notice any problems with this new version.

  • Like 2

Share this post


Link to post
Share on other sites

Hey @adrian. I installed the new version from Github. There is a small bug that I found:

If I create a user and don't send him a welcome message, then the next time I edit this user (maybe I want to add some details to custom fields) the label of the email function reads "Re-send welcome message" although I did not send an email yet.

Feature request:

If "Generate password" is checked, and the "PasswordForceChange" module is installed, the checkbox "Force password change on next login" should be checked, because it is not save, to send passwords via email. But maybe that is just my opinion. What do you think of that?

  • Like 1

Share this post


Link to post
Share on other sites

Here is another one: If I create a user via the API and use $new_user->sendEmail = true; an email is not being sent.

Here is the code that I execute via Tracy console:

$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "aceman3000@gmail.com";
$new_user->name ="aceman3000-gmail.com";
$new_user->sendEmail = true;
$new_user->save();

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi @jmartsch - looks like those recent changes broke a few things - sorry about that, but thanks for testing. Taking a look now.

Share this post


Link to post
Share on other sites

Ok @jmartsch, getting through these:

3 hours ago, jmartsch said:

If I create a user and don't send him a welcome message, then the next time I edit this user (maybe I want to add some details to custom fields) the label of the email function reads "Re-send welcome message" although I did not send an email yet.

Not sure how to handle this - the label changes from "Send" to "Resend" once the user has been published. I don't otherwise store a record of the email being sent. Sure it's possible, but I think it might get unnecessarily complicated. Do you have any thoughts for how it could be implemented well?

 

4 hours ago, jmartsch said:

Feature request:

If "Generate password" is checked, and the "PasswordForceChange" module is installed, the checkbox "Force password change on next login" should be checked, because it is not save, to send passwords via email. But maybe that is just my opinion. What do you think of that?

EmailNewUser respects the "Automatic Force Change" option in the PasswordForceChange module which ensures it is automatically checked when a new user is created. Does that work for you? I am hesitant to override that setting if it's intentionally unchecked. What do you think?

 

4 hours ago, jmartsch said:

Another bug: If you choose to re-send the welcome message, a new password is not generated.

Thank you - that is a new bug - because the password was populating the pass fields, rather than being generated on publish. Now it will generate if nothing is already set, which is the case when re-sending the welcome message.

 

4 hours ago, jmartsch said:

Here is another one: If I create a user via the API and use $new_user->sendEmail = true; an email is not being sent.

Here is the code that I execute via Tracy console:


$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "aceman3000@gmail.com";
$new_user->name ="aceman3000-gmail.com";
$new_user->sendEmail = true;
$new_user->save();

 

Thanks - there are two things going on here. I broke this when I moved all the hooks yesterday from ready() to init(). I have fixed this now, but the other thing is that you are missing this:

$modules->get("EmailNewUser"); // call the module since it is not autoload on the front end

I just tested with your code with this on top in Tracy's console and it's now working fine.

Please test the latest version and let me know how you go.

Share this post


Link to post
Share on other sites
22 minutes ago, adrian said:
4 hours ago, jmartsch said:

Feature request:

If "Generate password" is checked, and the "PasswordForceChange" module is installed, the checkbox "Force password change on next login" should be checked, because it is not save, to send passwords via email. But maybe that is just my opinion. What do you think of that?

EmailNewUser respects the "Automatic Force Change" option in the PasswordForceChange module which ensures it is automatically checked when a new user is created. Does that work for you? I am hesitant to override that setting if it's intentionally unchecked. What do you think?

Actually, maybe the solution here is another config setting in EmailNewUser. The setting would force automatic selection of "Force password change on next login", even if the "Automatic Force Change" option isn't checked in the PasswordForceChange module. Do you think this would work ok?

Share this post


Link to post
Share on other sites

Hey @adrian. The password generation in the latest version does not work correctly. It only generates passwords that are 1 char long.

In line https://github.com/adrianbj/EmailNewUser/blob/master/EmailNewUser.module#L158 you generate the new password. The output of 

bd($this->wire('fields')->get('pass')->minlength);

is null. If I try to insert a number instead, it works.

 $newPass = $this->passwordGenerator(6, false, $this->buildPasswordCharacterSets($this->wire('fields')->get('pass')));

I get back to the other questions soon.

Share this post


Link to post
Share on other sites

Hi @jmartsch - I can't seem to reproduce this - it always returns the correct value from the "pass" field's settings. I tried an API send and a Re-send message and they both returned 10 correctly.

In my case it is set to 10. Any chance your pass field is set to 1, or it's not named "pass".

What happens if you do: 

d($fields->get('pass')->minlength);

in the Tracy Console panel?

59f72a3c2a01d_ScreenShot2017-10-30at6_33_26AM.png.548dc5754c150787540faa72378716b0.png

Share this post


Link to post
Share on other sites

Actually, I think there is a bigger issue at hand - setting the password generator to less than 8 characters results in "too weak" from the PW password validation, so I am going to force the number of characters higher for the automatic generation. After all,  this is only meant to be a temporary password so probably no real need to worry because users will be copying/pasting anyway.

I'll commit an update shortly. Hopefully this will deal with your issue anyway, although it would still be nice to know why you are getting "1".

Share this post


Link to post
Share on other sites

Ok, new version committed. I am now forcing more complex password generation. Using the settings from the "pass" field just weren't working well - often not complex enough for the complexity validation, but should be good now.

Share this post


Link to post
Share on other sites

Adrian, thank you for your support. The new version is generating the password fine.

But now the problem is back that no email is being sent when I create the user via the API :(

Here is the code, that I used to test this:

$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "someone@somewhere.com";
$new_user->name ="someone-somewhere.com";
$new_user->sendEmail = true;
$new_user->save();

In a fresh PW 3.0.80 install I tried the latest version 1.1.2 and the output of 

d($fields->get('pass')->minlength);

is still "null". If I output only the field, I get the following data (see screenshot).

chrome_2017-10-30_15-20-53.png

Share this post


Link to post
Share on other sites
1 minute ago, jmartsch said:

But now the problem is back that no email is being sent when I create the user via the API

Don't forget that you need: 

$modules->get("EmailNewUser");

Are you using that and it's still not working?

As for the minlength thing - I get the feeling that maybe you're using a version of PW without those newish settings? This is what I see.

59f73b7c92c94_ScreenShot2017-10-30at7_45_26AM.png.e8c36438f4fe522c8ea79eb3723896e3.png

 

Share this post


Link to post
Share on other sites

Thanks. I did not use 

$modules->get("EmailNewUser");

because I previously changed the module to autoload, but after the updates this setting was gone. Thanks for the hint.

I am using latest ProcessWire Dev version from Github which is 3.0.80

And my settings look like in my screenshot. I am on a Windows System if that matters. But I don't think so.

After going into the pass field and saving the settings my bar dump now shows the same settings as yours. But these settings seem to be not available by default.

image.png.9231233fce20266b31fbde4e0c6e8073.png

Share this post


Link to post
Share on other sites

Even when I use:

$modules->get("EmailNewUser");
$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "someone@somewhere.com";
$new_user->name ="someone-somewhere.com";
$new_user->sendEmail = true;
$new_user->of(true);
$new_user->save();

in Tracy console, the mail is not being sent. Or do I do something wrong?

Share this post


Link to post
Share on other sites
9 minutes ago, jmartsch said:


 

because I previously changed the module to autoload, but after the updates this setting was gone. Thanks for the hint.

Glad that sorted things out. I could possibly make it optionally autoloaded on the frontend, but I figure that loading it manually like that is an acceptable approach - any strong thoughts on this?

9 minutes ago, jmartsch said:

After going into the pass field and saving the settings my bar dump now shows the same settings as yours. But these settings seem to be not available by default.

Interesting - is this site upgraded from an old PW version before these settings were available, or is it a new install? I wonder if that's the reason, but also wonder if it's something that the PW System Updater should have taken care of when you upgraded - maybe something to bring up with Ryan? Either way, it's good to know. I am no longer relying on these settings - all I am doing now is adding "symbols/puctuation" if selected, and using a higher min password length if it's set higher than the 12 which I am forcing as a minimum.

Share this post


Link to post
Share on other sites
5 minutes ago, jmartsch said:

Even when I use:


$modules->get("EmailNewUser");
$new_user = new User();
$new_user->of(false);
$new_user->addRole("editor");
$new_user->email = "someone@somewhere.com";
$new_user->name ="someone-somewhere.com";
$new_user->sendEmail = true;
$new_user->of(true);
$new_user->save();

in Tracy console, the mail is not being sent. Or do I do something wrong?

When I try that I get this error: 

Exception: Can’t save page 0: /admin/access/users/adrian5/: Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved. [roles] on line: 500 in /Users/ajones/Sites/ecoreportcard/wire/core/PagesEditor.php

59f74094c5c5c_ScreenShot2017-10-30at8_08_50AM.png.5dc76bf037829fa5d1fc2a80af8e2819.png

 

So, it's pretty clear that you can't turn outputformatting back on before saving (line 9). Do you not see that error in the Tracy console output?

Share this post


Link to post
Share on other sites

Yes, I removed that line, but email is still not being sent.

I even set autoload to true in the settings file, but that changes nothing.

Don't know why the email is not sent

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      First a note about my other modules...
      I have three existing modules that are similar in that they allow restrictions to be placed on repeating inputfields: Limit Repeater, Limit PageTable, Limit Table
      Restrict Repeater Matrix takes a different approach to the module configuration from those other modules. The module settings for Restrict Repeater Matrix are applied in the field settings rather in a module config screen. I think this new approach is better, but it means that it isn't practical to create different settings for different roles via the admin interface. Instead the module has a hookable method, allowing roles to be targeted and other advanced usages to be achieved via a hook. The result is that the module is more flexible.
      I intend to transition my other modules to the same approach over the coming weeks, but because this will result in breaking changes I will be releasing the updated modules under new names ("Restrict Repeater", etc) to avoid users upgrading via the Upgrades module without full awareness of the changes. The old modules will be marked as deprecated.
      Restrict Repeater Matrix
      A module for ProcessWire CMS/CMF. Allows restrictions and limits to be placed on Repeater Matrix fields. Requires ProcessWire >= v3.0.0 and FieldtypeRepeaterMatrix >= v0.0.5.
      For any matrix type in a Repeater Matrix field you have the option to:
      Disable settings for items (cannot change matrix type) Prevent drag-sorting of items Prevent cloning of items Prevent toggling of the published state of items Prevent trashing of items Limit the number of items that may be added to the inputfield. When the limit is reached the "Add new" button for the matrix type will be removed and the matrix type will not be available for selection in the "Type" dropdown of other matrix items. Please note that restrictions and limits are applied with CSS/JS so should not be considered tamper-proof.
      Usage
      Install the Restrict Repeater Matrix module.
      For each matrix type created in the Repeater Matrix field settings, a "Restrictions" fieldset is added at the bottom of the matrix type settings:

      For newly added matrix types, the settings must be saved first in order for the Restrictions fieldset to appear. Set restrictions for each matrix type as needed. A limit of zero means that no items of that matrix type may be added to the inputfield.
      Setting restrictions via a hook
      Besides setting restrictions in the field settings, you can also apply or modify restrictions by hookingRestrictRepeaterMatrix::checkRestrictions. This allows for more focused restrictions, for example, applying restrictions depending on the template of the page being edited or depending on the role of the user.
      The checkRestrictions() method receives the following arguments:
      $field This Repeater Matrix field $inputfield This Repeater Matrix inputfield $matrix_types An array of matrix types for this field. Each key is the matrix type name and the value is the matrix type integer. $page The page that is open in ProcessPageEdit The method returns a multi-dimensional array of matrix types and restrictions for each of those types. An example of a returned array:

      Example hooks
      Prevent the matrix type "images_block" from being added to "my_matrix_field" in a page with the "basic-page" template:
      $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $page = $event->arguments('page'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && $page->template->name === 'basic-page') { $type_restrictions['images_block']['limit'] = 0; } $event->return = $type_restrictions; }); Prevent non-superusers from trashing any Repeater Matrix items in "my_matrix_field":
      $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && !$this->user->isSuperuser()) { foreach($type_restrictions as $key => $value) { $type_restrictions[$key]['notrash'] = true; } } $event->return = $type_restrictions; }); http://modules.processwire.com/modules/restrict-repeater-matrix/
      https://github.com/Toutouwai/RestrictRepeaterMatrix
    • By BitPoet
      Here's a little text formatter module that redirects all external links found in a textarea (e.g. for hit counting) to a given URL.
      TextformatterExternalRedirect
      GitHub repo
      As TextFormatters do, this module modifies the contents of the textarea (HTML) at rendering time. It prepends the given URL to the link address for external links (http and https), optionally makes sure that the link is opened in a new window and allows you to add css classes to such links.
      All options can be configured in the module's configuration settings.
      Usage:
      Download the zip archive and extract it to site/modules, the rename the top folder to TextformatterExternalRedirect Go to the backend and select "Modules" -> "Refresh", then click "Install" for "External Link Redirect" Click "Settings" and configure the module
      Go into the field configuration for the field(s) you want this formatter to apply to and add it from the dropdown
      Done, now any external links in the configured fields will have the configured settings applied Feel free to leave feedback and post and questions you have here.
       
    • By teppo
      Hey folks!
      Took a couple of late nights, but managed to turn this old gist of mine into a proper module. The name is SearchEngine, and currently it provides support for indexing page contents (into a hidden textarea field created automatically), and also includes a helper feature ("Finder") for querying said contents. No fancy features like stemming here yet, but something along those lines might be added later if it seems useful (and if I find a decent implementation to integrate).
      Though the API and selector engine make it really easy to create site search pages, I pretty much always end up duplicating the same features from site to site. Also – since it takes a bit of extra time – it's tempting to skip over some accessibility related things, and leave features like text highlighting out. Overall I think it makes sense to bundle all that into a module, which can then be reused over and over again 🙂
      Note: markup generation is not yet built into the module, which is why the examples below use PageArray::render() method to produce a simple list of results. This will be added later on, as a part of the same module or a separate Markup module. There's also no fancy JS API or anything like that (yet).
      This is an early release, so be kind – I got the find feature working last night (or perhaps this morning), and some final tweaks and updates were made just an hour ago 😅
      GitHub repository: https://github.com/teppokoivula/SearchEngine Modules directory: https://modules.processwire.com/modules/search-engine/ Demo: https://wireframe-framework.com/search/ Usage
      Install SearchEngine module. Note: the module will automatically create an index field install time, so be sure to define a custom field (via site config) before installation if you don't want it to be called "search_index". You can change the field name later as well, but you'll have to update the "index_field" option in site config or module settings (in Admin) after renaming it.
      Add the site search index field to templates you want to make searchable. Use selectors to query values in site search index. Note: you can use any operator for your selectors, you will likely find the '=' and '%=' operators most useful here. You can read more about selector operators from ProcessWire's documentation.
      Options
      By default the module will create a search index field called 'search_index' and store values from Page fields title, headline, summary, and body to said index field when a page is saved. You can modify this behaviour (field name and/or indexed page fields) either via the Module config screen in the PocessWire Admin, or by defining $config->SearchEngine array in your site config file or other applicable location:
      $config->SearchEngine = [ 'index_field' => 'search_index', 'indexed_fields' => [ 'title', 'headline', 'summary', 'body', ], 'prefixes' => [ 'link' => 'link:', ], 'find_args' => [ 'limit' => 25, 'sort' => 'sort', 'operator' => '%=', 'query_param' => null, 'selector_extra' => '', ], ]; You can access the search index field just like any other ProcessWire field with selectors:
      if ($q = $sanitizer->selectorValue($input->get->q)) { $results = $pages->find('search_index%=' . $query_string . ', limit=25'); echo $results->render(); echo $results->renderPager(); } Alternatively you can delegate the find operation to the SearchEngine module as well:
      $query = $modules->get('SearchEngine')->find($input->get->q); echo $query->resultsString; // alias for $query->results->render() echo $query->pager; // alias for $query->results->renderPager() Requirements
      ProcessWire >= 3.0.112 PHP >= 7.1.0 Note: later versions of the module may require Composer, or alternatively some additional features may require installing via Composer. This is still under consideration – so far there's nothing here that would really depend on it, but advanced features like stemming most likely would.
      Installing
      It's the usual thing: download or clone the SearchEngine directory into your /site/modules/ directory and install via Admin. Alternatively you can install SearchEngine with Composer by executing composer require teppokoivula/search-engine in your site directory.
    • By teppo
      MarkupMenu is a markup module for generating menu trees. When provided a root page as a starting point, it generates a navigation tree (by default as a HTML "<ul>" element wrapped by a "<nav>" element) from that point onwards. If you've also provided it with current (active) page, the menu will be rendered accordingly, with current item highlighted and items rendered up to that item and its children (unless you disable the "collapsed" option, in which case the full page tree will be rendered instead).
      Modules directory: https://modules.processwire.com/modules/markup-menu/ GitHub repository: https://github.com/teppokoivula/MarkupMenu Usage
      As a markup module, MarkupMenu is intended for front-end use, but you can of course use it in a module as well. Typically you'll only need the render() method, which takes an array of options as its only argument:
      echo $modules->get('MarkupMenu')->render([ 'root_page' => $pages->get(1), 'current_page' => $page, ]); Note: if you omit root_page, site root page is used by default. If you omit current_page, the menu will be rendered, but current (active) page won't be highlighted etc.
      A slightly more complex example, based on what I'm using on one of my own sites to render a (single-level) top menu:
      echo $modules->get('MarkupMenu')->render([ 'current_page' => $page, 'templates' => [ 'nav' => '<nav class="{classes} menu--{menu_class_modifier}" aria-label="{aria_label}">%s</nav>', 'item_current' => '<a class="menu__item menu__item--current" href="{item.url}" tabindex="0" aria-label="Current page: {item.title}">{item.title}</a>', ], 'placeholders' => [ 'menu_class_modifier' => 'top', 'aria_label' => 'Main navigation', ], 'include' => [ 'root_page' => true, ], 'exclude' => [ 'level_greater_than' => 1, ], ]); Note: some things you see above may not be entirely sensible, such as the use of {menu_class_modifier} and {aria_label} placeholders. On the actual site the "nav" template is defined in site config, so I can define just these parts on a case-by-case basis while actual nav markup is maintained in one place.
      Please check out the README file for available render options. I'd very much prefer not to keep this list up to date in multiple places. Basically there are settings for defining "templates" for different parts of the menu (list, item, etc.), include array for defining rules for including in the menu and exclude array for the opposite effect, classes and placeholders arrays for overriding default classes and injecting custom placeholders, etc. 🙂
      MarkupMenu vs. MarkupSimpleNavigation
      TL;DR: this is another take on the same concept. There are many similarities, but also some differences – especially when it comes to the supported options and syntax. If you're currently using MarkupSimpleNavigation then there's probably no reason to switch over.
      I'd be surprised if someone didn't draw lines between this module and Soma's awesome MarkupSimpleNavigation. Simply put I've been using MSN (...) for years, and it's been great – but there are some issues with it, particularly in the markup generation area, and it also does some things in a way that doesn't quite work for me – the xtemplates thing being one of these. In some ways less about features, and more about style, I guess 🙂
      Anyhow, in MarkupMenu I've tried to correct those little hiccups, modernise the default markup, and allow for more flexibility with placeholder variables and additional / different options. MarkupMenu was built for ProcessWire 3.0.112+ and with PHP 7.1+ in mind, it's installable with Composer, and I have a few additional ideas (such as conditional placeholders) still on my todo list.
      One more small(ish) difference is that MarkupMenu supports overriding default options via $config->MarkupMenu. I find myself redefining the default markup for every site, which until now meant that each site had a wrapper function for MarkupSimpleNavigation (to avoid code / config repetition), and this way I've been able to leave that out 🙂
      Requirements
      ProcessWire >= 3.0.112 PHP >= 7.1.0 If you're working on an earlier version of ProcessWire or PHP, use MarkupSimpleNavigation instead.
    • By teppo
      Hey folks!
      I'm happy to finally introduce a project I've been working on for quite a while now: it's called Wireframe, and it is an output framework for ProcessWire.
      Note that I'm posting this in the module development area, maily because this project is still in rather early stage. I've built a couple of sites with it myself, and parts of the codebase have been powering some pretty big and complex sites for many years now, but this should still be considered a soft launch 🙂
      --
      Long story short, Wireframe is a module that provides the "backbone" for building sites (and apps) with ProcessWire using an MVC (or perhaps MVVM – one of those three or four letter abbreviations anyway) inspired methodology. You could say that it's an output strategy, but I prefer the term "output framework" since in my mind the word "strategy" means something less tangible. A way of doing things, rather than a tool that actually does things.
      Wireframe (the module) provides a basic implementation for some familiar MVC concepts, such as Controllers and a View layer – the latter of which consists of layouts, partials, and template-specific views. There's no "model" layer, since in this context ProcessWire is the model. As a module Wireframe is actually quite simple – not even nearly the biggest one I've built – but there's still quite a bit of stuff to "get", so I've put together a demo & documentation site for it at https://wireframe-framework.com/.
      In addition to the core module, I'm also working on a couple of site profiles based on it. My current idea is actually to keep the module very light-weight, and implement most of the "opinionated" stuff in site profiles and/or companion modules. For an example MarkupMenu (which I released a while ago) was developed as one of those "companion modules" when I needed a menu module to use on the site profiles.
      Currently there are two public site profiles based on Wireframe:
      site-wireframe-docs is the demo&docs site mentioned above, just with placeholder content replaced with placeholder content. It's not a particularly complex site, but I believe it's still a pretty nice way to dig into the Wireframe module. site-wireframe-boilerplate is a boilerplate (or starter) site profile based on the docs site. This is still very much a work in progress, but essentially I'm trying to build a flexible yet full-featured starter profile you can just grab and start building upon. There will be a proper build process for resources, it will include most of the basic features one tends to need from site to site, etc. --
      Requirements and getting started:
      Wireframe can be installed just like any ProcessWire module. Just clone or download it to your site/modules/ directory and install. It doesn't, though, do a whole lot of stuff on itself – please check out the documentation site for a step-by-step guide on setting up the directory structure, adding the "bootstrap file", etc. You may find it easier to install one of the site profiles mentioned above, but note that this process involves the use of Composer. In the case of the site profiles you can install ProcessWire as usual and download or clone the site profile directory into your setup, but after that you should run "composer install" to get all the dependencies – including the Wireframe module – in place. Hard requirements for Wireframe are ProcessWire 3.0.112 and PHP 7.1+. The codebase is authored with current PHP versions in mind, and while running it on 7.0 may be possible, anything below that definitely won't work. A feature I added just today to the Wireframe module is that in case ProcessWire has write access to your site/templates/ directory, you can use the module settings screen to create the expected directories automatically. Currently that's all, and the module won't – for an example – create Controllers or layouts for you, so you should check out the site profiles for examples on these. (I'm probably going to include some additional helper features in the near future.)
      --
      This project is loosely based on an earlier project called pw-mvc, i.e. the main concepts (such as Controllers and the View layer) are very similar. That being said, Wireframe is a major upgrade in terms of both functionality and architecture: namespaces and autoloader support are now baked in, the codebase requires PHP 7, Controllers are classes extending \Wireframe\Controller (instead of regular "flat" PHP files), implementation based on a module instead of a collection of drop-in files, etc.
      While Wireframe is indeed still in a relatively early stage (0.3.0 was launched today, in case version numbers matter) for the most part I'm happy with the way it works, and likely won't change it too drastically anytime soon – so feel free to give it a try, and if you do, please let me know how it went. I will continue building upon this project, and I am also constantly working on various side projects, such as the site profiles and a few unannounced helper modules.
      I should probably add that while Wireframe is not hard to use, it is more geared towards those interested in "software development" type methodology. With future updates to the module, the site profiles, and the docs I hope to lower the learning curve, but certain level of "developer focus" will remain. Although of course the optimal outcome would be if I could use this project to lure more folks towards that end of the spectrum... 🙂
      --
      Please let me know what you think – and thanks in advance!
×
×
  • Create New...