Jump to content

Soma

Moderators
  • Posts

    6,808
  • Joined

  • Last visited

  • Days Won

    159

Everything posted by Soma

  1. $page->createdUser is a method to get the user object and has nothing to do with the field $page->created_users_id you can use in selectors.
  2. From the module interface /** * Method to initialize the module. * * While the method is required, if you don't need it, then just leave the implementation blank. * * This is called after ProcessWire's API is fully ready for use and hooks. It is called at the end of the * bootstrap process. This is before PW has started retrieving or rendering a page. If you need to have the * API ready with the $page ready as well, then see the ready() method below this one. * */ public function init();
  3. You're welcome. Ryan, you just have to look at what you take from my PR, because I think you modified some of the files at the same time. Also you may have to check if the code really makes sense and maybe something missing an isset() or alike. I just done it real quick and only tested with multilanguage on.
  4. I'm using this feature quite a lot. Here's an example of creating a indented list for using with checkboxes, selects. IT creates a new PageArray and modifies the "title" to indent, and here with a (count) used in the context of the categories to see how many products are under that category. $children = $pages->get("/shop/")->children(); $list = new PageArray(); function mylist($children, $ind='', $arr){ $ind .= "– "; foreach($children as $cat) { $countproducts = wire("pages")->find("template=product,categories=$cat")->count(); $cat->title = $ind . $cat->title . " ($countproducts)"; $arr->add($cat); if($cat->numChildren) { mylist($cat->children,$ind, $arr); } } return $arr; } return mylist($children, $ind='',$list); This will produce something like –– Gewürze (0) –– –– Kräuter (27) –– –– Kräutermischungen (7) –– –– Einzelgewürze (0) –– –– –– Anis (2) –– –– –– Blaumohnsaat (1) –– –– –– Bockshornsamen (2) –– –– –– Chili (16) –– –– –– Glutamat (1) –– –– –– Galgantwurzel (3) –– –– –– Ingwer (4) –– –– –– Kardamom (4) –– –– –– Knoblauch (5) –– –– –– Koriander (2) –– –– –– Kurkuma (2)
  5. Welcome @peterofeng I'm not sure I understand <div> {$page->title}</h3> <ul> <li>Sub item 1</li> <li>Sub item 2</li> <li>Sub item 3</li> </ul> <div> <div> {$page->title}</h3> <ul> <li>Sub item 1</li> <li>Sub item 2</li> <li>Sub item 3</li> </ul> <div> This isn't a 2 level navigation. And the UL you could generate with the module but just for a simple navigation like this you could make it with your own simple foreach code. <ul> <li>item 1</li> <li class="even">item 2</li> <li>item 3</li> <li class="even">item 4</li> </ul> Same with this. It isn't supported by the module, but you could simply use css nth-child(odd) or jQuery to produce this. Not exactly sure, but you could try: 'selector' => 'parent!=1022|1002'
  6. Ryan in my tests, this doesn't work as in your examples. $template = $templates->get('basic-page'); $p = $pages->getById(1386, $template)->first(); The page 1386 has the template "basic-page" but the query doesn't return it. But it does find it when using this: $template = $templates->get('basic-page'); $p = $pages->getById(array(1386), $template)->first(); BUT it also returns the page when I specify a wrong template $template = $templates->get('custom'); $p = $pages->getById(array(1386), $template)->first(); I'm not sure what all about it when using id's to retrieve a page how would a template be of any benefit?
  7. It is a CMS page after all and not a front-end from where you make submission and it won't get sent before all errors are corrected. I understand what you're saying and in future this for sure will be possible. Currently publish/unpublished, creating, editing page is limited to that there's only one version of a page and one status. So editing a page and not being able to save it because a field is not valid may cause issues and keeps the page in a state the user can't go on (maybe he doesn't know etc) and all data will get lost. Anyway many scenarios and things that can happen with such validation. Saving in session wouldn't scale. It's not as simple and we're even in a privileged situation where PW at least has validation and field dependencies etc, I don't know of a similar CMS that has this anyway. PW is designed to do it all and more you can't even dream of , but Ryan has only two hands and one brain, 16 hours a day. But I'm sure he could provide more and better worded answers than me. Yes exactly: versioning/draft versions of pages will for sure give you more what you need here.
  8. I don't know how to prevent page from getting saved. Whatever you mean by definition "save page". What about other fields that are correct and edited, they will get lost? So PW will save page regardless, except for fields that are validated, the inputfield processInput defines what get's saved (not sure in details and have no time to test out). But required fields will just throw an error. So in this case PW saves the page but you won't be able to publish it until all "validation/required" errors are gone, only then the page can be published. So whatever you do with old and new value is up to you. As soon as you throw an error PW says this: Session: Change: body Session: Saved Page: /de/about/ (1 change) - Cannot be published until errors are corrected Session: Go away! (body)
  9. http://modules.processwire.com/modules/service-pages/ In the screenshot I see "Fields that may be queired by..." I see a "parent" ... So I think you should be able to "&parent=1001" and get the children of 1001.
  10. Hmm old value -> new value. before editing -> after editing Current value -> edited value but not yet saved
  11. Ok I tested again with another install. When viewing page on default language (/de/about/), and in template create or edit a page (always with API): 1. creating page works fine, language is same before and after 2. editing the page and modifying the title of each language, I get the famous error 3. when removing repeater from template, it works, no error When viewing page on alternative language (/en/about/), and in template create or edit a page 1. creating fails, error 2. editing fails, error 3. when removing repeater, it works fine Hope this help you reproduce
  12. Hmm. Just from API side (see code examples I posted) when editing or creating a page with repeater. Repeater isn't populated (see my code) and the repeater has title language field. The repeater has 3 items ready. I think I provided all informations in above posts and I don't know what else I can give without repeating. :/ No, I don't know if other factors than removing repeater change behaviour. As soon as I remove repeater it works fine, add it back and it throws error.
  13. Me again. I glimpsed at what you already done with that "wrapper". I now got it working for TinyMCE links plugin. So it will create localized urls when selecting from the page tree. I had to modify a couple files to add a langID option to ProcessPageList and ProcessPageEditLink. Should I just make a pull request with those changes so you can look at and test? Edit: Pull Request done https://github.com/ryancramerdesign/ProcessWire/pull/241
  14. Ryan, this is a very important feature to complete the language support. I'm currently working on a multilanguage project that will maybe need to have links localized in TinyMCE. Can I somehow help with this? I'm not sure what you already have done, but will take a look. Any pointer would be greatly appreciated.
  15. Yeah of course you could just output scripts along with the "form" output. Thanks apeisa for throwing that in. That being said, there's not many modules that generate markup apart from this module and the case where a module needs to output code in the template is rare but of course possible (using render hook). I think if you use this shop module you anyway need to create templates and template code to make it work and adding a line or more to account for scripts is not that bad at all. PW gives you flexibility here as it doesn't dictate how you need to use it. In case of the shop module it is also possible to create you own markup for all the cart, checkout etc and only use the low level functions provided by the modules.
  16. Usually this is a good and simple method: In a autoload module you hook into the processInput of InputfieldTextarea. public function init(){ $this->addHookAfter("InputfieldTextarea::processInput", $this, "validateText"); } public function validateText($event){ $field = $event->object; if($field->name == "body"){ $page = $this->modules->ProcessPageEdit->getPage(); $oldValue = $page->get("$field->name"); $newValue = $field->value; echo "old value: " . $oldValue; echo "new value: " . $newValue; if($newValue !== $oldValue){ $field->value = $oldValue; $field->error("Go away!"); } } } For a error message you simply add error("text") to the field. It will get showed after saving. What this examples also shows nicely is how to get the old value and new value. The code may slightly varies for different type of fields but the principle is always the same. There's also a method to hook into Pages::saveReady() but I'm not sure what the advanced really are atm.
  17. Soma

    Avatar for pwired

    At least he hasx a avatar.
  18. vxda glad you figured it out. It's always good to check if there's images, you could also use count(), and maybe also not output the image if there's no image. So you could also do ... $out .= "<li><div><a href='{$newsitem->url}'>"; if ($newsitem->images->count()) { $out .= "<img src='{$newsitem->images->first->size(313,177)->url}'/>"; } $out .= "{$newsitem->title}"; ...
  19. .. had to run .. so if we go from the default PW site setup with head.inc and foot.inc in your sc-checkout.php you would do it like this: $checkout = $modules->ShoppingCheckout->renderCheckout(); include("./head.inc"); echo $checkout; include("./foot.inc"); If you want to add the scripts getting loaded in header in head.inc If you have your scripts before </body> in foot.inc you can also do include("./head.inc"); echo $modules->ShoppingCheckout->renderCheckout(); include("./foot.inc");
  20. Since it wouldn't be autoload, It will only get loaded after when you call checkout render in your template. So as I mentioned it would have to be after the echo $modules->ShoppingCheckout->renderCheckout();. If you have the script output before it won't work. It depends how you use templates, and the order is important.
  21. Ah sorry for the typo!
  22. try $input->urlSegmentsStr $input->urlSegmentStr #280 WireInput.php
  23. Yeah I understand your point and I provided the best/correct solution, so you could make your payment module autoload and add hooks. So should be no big deal. This isn't the official shop module thread btw. Users/admins don't have access to install modules only superusers. So this is usually the site builder that is concerned about installing modules. Adding a line to the templates and be done with it when setting it up makes it a lot more modular at the end. With doing this to add script via a render hook as you said it's a "hack" that has several drawbacks. - render hook might get called 2 times, if one decided to use a $page->render() mvc approach to render pages, so the scripts will get added 2 times - as you said, scalability, it may not important with 1 module on 1 page but you get it - if you have multiple payment modules doing what you do, they will all add scripts, so you also have to check for what payment module is selected. I agree it's a little different topic, but the best way is what I showed using $config->scripts, $config->styles. Ultimately it's also what PW admin is doing. Through a render hook might be ok in cases but I wouldn't settle on that as a best practice.
  24. What you mean by "you have to integrate that code line in the template header" ? Why is this bad? (You can also use it for other cases where you need to add scripts.)
  25. But the autoload feature makes it load on every request. If you're happy with that So you'd have to restrict it to the particular page, parse and add the html to the page. Here's a better approach: Load the script to $config->scripts->add("url/to/script.js"); public function init() { $this->config->scripts->add($this->config->urls->PaymentExample . "script.js"); } and adding this to where the scripts should be loaded in the template file: <?php foreach($config->scripts->unique() as $file) echo "\n\t<script type='text/javascript' src='$file'></script>"; ?> after the checkout module render call of course. This is also used by the admin to add and load scripts and css from modules.
×
×
  • Create New...