Leaderboard
Popular Content
Showing content with the highest reputation on 05/10/2022 in all areas
-
Now it makes sense. I thought "ModuleConfigInputfields" are classes constant. That now I understood, thanks.2 points
-
I can confirm I use this a lot too!! It also merges updates on fields and templates. I think the only caveat I have is that it doesn't work 100% with FieldtypeOptions. And the pages import/export is crazy good, works with absolutely every native field I've tested with, even complex Repeater Matrix/Repeaters. I just recently used it to migrate some old sites, into a new "template field schema" and I cannot even estimate how much work it saved lol2 points
-
@Matzn that not.how obj inheritennce work { .clsses inherit code not runs time valus } class A{public $foo;} class B extends A{} $a=new A(); $a->foo='Foo'; $b=new B(); echo $a->foo; // 'Foo' echo $b->foo; // emptys.. nothing modules work.same { .mabe.u want this in you TestModuleChild ? } >>> public function __construct(){ $this->setArray($this->modules->getConfig('TestModule')); }2 points
-
@Matzn Your TestModuleChild.module is overriding the getModuleConfigInputfields() of the TestModule.module and replacing it. In PHP, if you want the parent method to run, then you need to either omit the method completely in your child class, or call the method parent::method() so that it will run (like what you are doing with your __construct method). What you are doing currently is replacing the method with one that has no code in it. What I think you are wanting is this in your TestModuleChild.module: public function getModuleConfigInputfields(InputfieldWrapper $inputfields) { parent::getModuleConfigInputfields($inputfields); } After doing the above, now it will inherit the code of the parent class. And after calling that parent::method() maybe you want to add another configuration setting to it, i.e. public function getModuleConfigInputfields(InputfieldWrapper $inputfields) { parent::getModuleConfigInputfields($inputfields); $f = $this->wire()->modules->get('InputfieldText'); $f->attr('name', 'test_field'); $f->label = 'Test field'; $f->val($this->test_field); $inputfields->add($f); } But if you don't want to add anything new to the getModuleConfigInputfields() then just leave the method out of your TestModuleChild.module completely, and it will inherit automatically. Also, module configuration data should be defined with runtime calls, so I recommend you remove this: public $field_1 = "parent module property 1"; and replace it with this in your __construct(): $this->set('field_1', 'parent module property 1'); I see you are using static getModuleInfo() methods in your classes. In cases where you've got one module extending another, unless the child module literally does an include() at the top of the parent module's file, then you should define your child module's info in a ModuleName.info.php file like I described in my previous message (including the 'requires' statement), and omit the getModuleInfo() static method. Otherwise, if PHP/PW happens to include() the child module before the parent module, you'll get a fatal class error. By using a separate ModuleName.info.php, PW can learn about the module without having to load the class file, and it can see from your 'requires' statement that it needs to load the parent module before your child module, ensuring no fatal errors. If you can't do this, or don't want to, then make sure your child module does an include() or require() of the parent module's file, somewhere before your "class TestModuleChild ...".2 points
-
ProcessWire also offers build in export and import functions for templates, fields and pages. ?2 points
-
2 points
-
2 points
-
Triasima, a portfolio management company, asked the agency Contractuelle to revamp its web image. Spiria was the contractor for the site integration. While seemingly straightforward, there were a few challenges ahead, including managing three distinct regions that shared a lot of content: Canada, the United States and the Rest of the World. Two of these regions were assigned a sub-domain (us. and world.). We did not need a multi-site module. Within each region, the visitor has to choose a type of investment profile. One of these profiles could only be selected by the Canadian region. Each profile shares some content but is identified by colour. In short, a small puzzle solved with very little code and CSS. We made extensive use of field repeaters to create a nice administration interface. We have designed "presentation scenarios" that allow the administrator to set up pages as they wish. Only the header and footer are fixed. https://triasima.com1 point
-
I think the error comes from trying to use PHP variables? I have approached this using the getSelectablePages hook and a couple others to enable dynamically adding them to different parents depending on their position within the tree,. (Bear with me since I am basing this example this from a very old project I have that "cascades" options into children page fields, it might not work exactly in a copy/paste fashion) Ok so this hook gets the pages only under the closest faq-parent of the current page with the reference field: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { $page = $event->arguments('page'); $event->return = $page->closest('template=faq-parent')->children('template=faq-category'); }); Now, the tricky part when doing this dynamically and adding new pages is selecting the right parent, which from some old code I have lying around has to be done sort of like this: $wire->addHookBefore('InputfieldPage::processInputAddPages', function($event) { $field = $event->object; $page = $field->hasPage; $parent_id = $page->closest('template=faq-parent'); $field->set("parent_id", $parent_id); }); And this last step I am not super sure, but I think it is needed to enable the Add New pages part. $wire->addHookBefore('InputfieldPage::renderAddable', function($event) { $field = $event->object; $page = $field->hasPage; $parent_id = $page->closest('template=faq-parent'); $field->set("parent_id", $parent_id); })1 point
-
Got it! Thanks so much for your @ryan. Thanks for the link too @AndZyk, that explains it really well.1 point
-
@DrQuincy Yes, sorry, it should be "return $this->halt();" rather than just $this->halt(), I have updated my example. If you don't do a return then it'll still do the same thing (see below), but instead it'll continue executing your code in that file after the halt() call. What $this->halt(); does is tell the current request not to render any more files. So if you call $this->halt(); from your template file, then it's not going to include any further files specified to render afterwards. For instance, it will skip rendering your _main.php file (if you are using one). But everything else about the request will continue normally, so it does a normal shutdown, etc.1 point
-
Here is the blog post about it: https://processwire.com/blog/posts/processwire-2.6.8-brings-new-version-of-reno-admin-theme-and-more/#new-this-gt-halt-method-for-use-in-template-files1 point
-
Mysterious, on my setup everything works fine. Please be patient, I will take a deeper look within the next days. Today I am to busy to dig in ;-) Best regards1 point
-
@fuzenco - new version just committed that also supports integer & decimal field types as well as float.1 point
-
@Matzn ProcessWire classes are just PHP classes, so there would be no difference. Note that I don't think you can have a class named "Parent" as I think that might be a reserved word in PHP. I wouldn't bother trying to do an external configuration class. Start with an internal getModuleConfigInputfields() method, and when all works, then consider moving it to an external one if needed. Make sure your module implements the ConfigurableModule interface, indicated at the top of the class. I also think maybe you shouldn't try to extend your Parent module/class and instead should just write another module that pulls from the Parent module what it needs. Module inheritance is useful in many situations but it's not clear to met that this is one of those situations, though I could be wrong. This is fine the way you are doing it, but note that your class "Child" need not extend "Parent" given the approach you are using. Your "Child" module could just extend WireData instead, and the code in your myMethode() would do exactly the same thing.1 point
-
@DrQuincy Is this from a template file? You could do this: echo "<p>An error occurred!</p>"; return $this->halt(); That halts the rendering of output but lets PW finish everything else in the request. Another option is to throw a WireException. This will also halt the request but allow PW to still shutdown. The response is an http 500 error. The error message will be displayed if in debug mode or if the user is logged in and a superuser. throw new WireException("An error occurred!"); Often times on the front end a fatal error is about a resource not available, and a 404 is the appropriate response. So you can do this: throw new Wire404Exception(); or this does the same thing (I prefer this shorter version): wire404(); Lastly, while the above are preferable, it's also okay to do an exit() or a die(), is shouldn't break anything at least.1 point
-
@Matzn Are you wanting a parent/child class relationship, or are parent and child modules separate modules where you want the child module to pull a value from the parent module? If you just want to pull a configuration value from "ParentModule" to use somewhere in "ChildModule" (or anywhere else) then you don't need to have a parent/child relationship between the modules and can instead just pull the value you need: $api_user = $modules->getConfig('ParentModule', 'api_user'); On the other hand, if you really do want a parent/child relationship between the module classes, and they will be two separate installed modules, then it is possible. Many Inputfield and Fieldtype modules use this approach. For instance, InputfieldCKEditor extends InputfieldTextarea, and InputfieldTextarea extends InputfieldText. The reason is that they all have similar configuration needs, as they are all inputs for text. InputfieldCKEditor builds upon the configuration of InputfieldTextarea and InputfieldTextarea builds upon the configuration of InputfieldText. When it's possible that someone might attempt to install the ChildModule without having first installed the ParentModule then it's recommended to keep your module-info in a separate php (or json) file like ModuleName.info.php, at least for the modules that require another (i.e. ChildModule requires ParentModule). This ensures that if ChildModule is on the file system, but ParentModule isn't, PW can identify the requirements for the ChildModule without having to load its class file. (If it loaded its class file, then it would result in an error since ChildModule extends ParentModule, and ParentModule isn't present, so that's why we want to avoid that). Let's say we've got this ParentModule: // ParentModule.module.php class ParentModule extends WireData implements Module, ConfigurableModule { public function __construct() { $this->set('api_user', ''); // establish default value parent::__construct(); } public function getModuleConfigInputfields(InputfieldWrapper $inputfields) { $f = $this->wire()->modules->get('InputfieldText'); $f->attr('name', 'api_user'); $f->label = 'API User'; $f->required = true; $f->val($this->get('api_user')); $inputfields->add($f); } } And it also has this ParentModule.info.php file to define module info. Since ParentModule doesn't extend another module, it could also be in a static getModuleInfo() method if you preferred it, but we'll stick to the file for this example: // ParentModule.info.php <?php namespace ProcessWire; $info = array( 'title' => 'Parent module', 'version' => 1, 'summary' => 'Parent module description', ); Here's a child module that extends ParentModule and also adds an "api_key" to the configuration: // ChildModule.module.php class ChildModule extends ParentModule implements Module, ConfigurableModule { public function __construct() { $this->set('api_key', ''); // default value parent::__construct(); } public function getModuleConfigInputfields(InputfieldWrapper $inputfields) { parent::getModuleConfigInputfields($inputfields); $f = $this->wire()->modules->get('InputfieldText'); $f->attr('name', 'api_key'); $f->label = 'API Key'; $f->required = true; $f->val($this->get('api_key')); $inputfields->add($f); } public function test() { $this->message("API user is $this->api_user and key is $this->api_key"); } } …and the ChildModule's info file is below. Note the "requires" that says it requires ParentModule: // ChildModule.info.php <?php namespace ProcessWire; $info = array( 'title' => 'Child module', 'version' => 1, 'summary' => 'Child module description', 'requires' => 'ParentModule', ); Zeka's example above is also a good one, but just adding my example as another variation.1 point
-
Like caniuse.com but for PHP, eg: https://caniphp.com/?s=null It is possible to support the project: https://ko-fi.com/magicroundabout https://github.com/rosswintle/can-i-php Happy coding! :)1 point
-
Hi @Matzn <?php namespace ProcessWire; class ParentModule extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return [ 'title' => 'Parent Module', 'version' => 1, ]; } const defaultValue = '12345'; public function __construct() { $this->set('api_user', self::defaultValue); // set default value in construct } public function getApiUser() { return $this->api_user; } public static function getModuleConfigInputfields(array $data) { if(!isset($data['api_user'])) $data['api_user'] = self::defaultValue; $form = new InputfieldWrapper(); $f = wire('modules')->get('InputfieldText'); $f->name = 'api_user'; $f->label = 'API USER'; $f->value = $data['api_user']; $form->add($f); return $form; } } <?php namespace ProcessWire; class ChildModule extends ParentModule { public static function getModuleInfo() { return [ 'title' => 'ChildModule', 'version' => 1 ]; } public function __construct() { parent::__construct(); bd($this->getApiUser()); bd($this->wire()->modules->getModuleConfigData('ParentModule')); } } Take a look at the construct method of ChildModule. Without calling parent::__construct you will not be able to get what you want. Also you can use $this->wire()->modules->getModuleConfigData('ParentModule') to get config data of module.1 point
-
I’ve got a request. I love this module and use it a few times a week. The problem I just encountered is that fields that are Floats cannot be selected and updated via the “Field Set or Search and Replace” option. I’d love to see Floats added.1 point
-
It's been a quiet week on the dev branch (mostly), and so this post will also be short. That's a good thing, as it means we are at a stage where there's no new major things to immediately fix or add. Assuming that remains the case, by next week at this time we should have 3.0.200 released on the main/master branch. In next week's post I plan to outline all that's changed since our last master version, 3.0.184, stay tuned and have a great weekend!1 point
-
1 point
-
The Problem was solved by https://github.com/processwire/processwire/commit/cde0f53ad60ac7a3bb62b42de5e151b7a6521caa1 point
-
Great site @heldercervantes ! One small thing, looks like there is a small logo displaying issue, on homepage path to logo image is: /site/templates/static/brand/logo.svg on subpages: /site/templates//static/brand/logo.svg Otherwise amazing work, Congrats!1 point
-
It doesn't look like there is a way to keep HTML comments intact when using the core Markup Regions feature. Even if there was a way to set the "exact" option you mentioned (which there isn't currently because the Markup Regions methods aren't hookable), comments are also removed here. You could make a feature request at GitHub for an option to keep HTML comments.1 point
-
One or more of these fields in your selector must be Page fields. If you are trying to match the title of the selected page(s) in your search then use a subfield selector for the page title. For example, instead of... $selector = "my_page_field~=$q"; ...do... $selector = "my_page_field.title~=$q"; I suspect that otherwise PW thinks that you might be trying to match the page ID to the number in your search query, which doesn't allow a ~= operator.1 point
-
@Atlasfreeman >called "textformatterSoundmanager-master" can this be the problem? yes, rename it "TextformatterSoundmanager" Also you have to output the CSS files - you can choose your output option in the module, but it won't look right without the CSS. So you can output the $config->styles, or use one of the options.. Let me know how it goes..0 points