-
Posts
6,798 -
Joined
-
Last visited
-
Days Won
158
Everything posted by Soma
-
I'm not sure I can follow your code correctly. But you do add config to the process module and to the textareas inputfield config? I'd expected you only add additional config to the inputfield.
- 20 replies
-
- hooks
- inputfields
-
(and 1 more)
Tagged with:
-
It's hard to follow what's going on in your modue and maybe it's just the order of how the hooks are called, but not sure. $this->addHookAfter('InputfieldTextarea::render', $this, 'hook_InputfieldTextarea_render'); $this->addHookAfter('ProcessPageEdit::execute', $this, 'hook_ProcessPageEdit_execute'); $this->addHookAfter('InputfieldTextarea::getConfigInputfields', function(HookEvent $event) { Also you're using a helper module in construct and in the config hook, I'm not sure what that does have an effect to that config system.
- 20 replies
-
- hooks
- inputfields
-
(and 1 more)
Tagged with:
-
I think using a Process module here for this adding config is the problem, to start with. Process modules are meant for a specific thing. As I said it might work for every module you try to build but it's not the way to go I think, they should be used as such. The hook to add config should be done via a WireData autoload=true module.
- 20 replies
-
- hooks
- inputfields
-
(and 1 more)
Tagged with:
-
Also I found after doing many modules that it often can get complex and you have to be careful with doing advanced stuff, it can easily break existing stuff. Sometimes just because it's working doesn't mean it's the correct way. But then it can often get very tricky since there's more than meets the eye. I always tried to look at ryan's modules and how certain things are solved. I think I understood most of this stuff, but even then I sometimes think I didn't at all.
- 20 replies
-
- 1
-
- hooks
- inputfields
-
(and 1 more)
Tagged with:
-
This works fine when done right: see https://github.com/boundaryfunctions/TextareaCounter I'm not sure a process module is the right job for all those things you have now in a Process module that is loaded on every page edit even if no textarea preview is needed. I would have separated things more clearly. I might be wrong but I still thinking process modules should be used as such, not autoload and provide functionality that is bound to a admin page or admin url.
- 20 replies
-
- 3
-
- hooks
- inputfields
-
(and 1 more)
Tagged with:
-
Kind boring sport you have here on earth. On my planet we also play a kind of "football", but it's called "airball". There's 42 players and the playing field is 3.1415 square kilometers. We use hover-boards and the ball is levitating. The goal is a circle and if the ball enters the goal, one player of the other team has to drink 1 cup of slime that contains 50% alcohol. Pretty damn fun. *hickup*
-
$pages->find("template=x, pagearrayfield=$somepage"); Where $somepage might be a page or a or multiples ID's . If $somepage is a page object, it will converted to a string with it's ID so you don't have to write $somepage->id but you could. $pages->find("template=x, pagearrayfield=1230"); $pages->find("template=x, pagearrayfield=1230|1233|1203");
-
Localized URL for page in bootstrapped external script
Soma replied to skidr0w's topic in Multi-Language Support
Had to take a quick look to remember how I've done it. Thing is the modules is loaded but the ready() is never triggered in bootstrap and those language aware API is only added via hooks. So I did add those hooks in my script and delegate the event to the module manually. <?php include("index.php"); $lang = wire("languages")->get("default"); // manually add hook to use localUrl wire()->addHook("Page::localUrl", null, function($event){ wire("modules")->LanguageSupportPageNames->hookPageLocalUrl($event); }); // now works echo wire("pages")->get(1001)->localUrl($lang); // ------- // manually add hook to use user language wire()->addHookAfter("Page::path", null, function($event){ wire("modules")->LanguageSupportPageNames->hookPagePath($event); }); // now works wire("user")->language = $lang; echo wire("pages")->get(1001)->url; -
Localized URL for page in bootstrapped external script
Soma replied to skidr0w's topic in Multi-Language Support
In a bootstrap the Module isnt loaded but you can load it manually in your script. $user doesn't exist in a bootstrap. Use wire("user") instead. -
5. It's in WireHttp WireHttp::download()
-
HelperFieldLinks add also a link to the template select field. http://modules.processwire.com/modules/helper-field-links/ I always thought and still think this should be something in core, but all we got is a hover on the field to show the field name as "text" appended to the label and only if in debug mode..
- 1 reply
-
- 2
-
Great! This opens new possibilities to actually use markdown and alike. I was thinking a some time about having something like this, looks very nice.
-
ProcessGetVideoThumbs - it looks like this module is the cause and should be in the thread title. Maybe first enable debug mode in site/config.php and look what error it throws, or ask the ProcessGetVideoThumbs module thread.
-
I think we are not really done yet. You mentioned that those fields are page fields? Well if the values all are page fields, this means you know the all the values ahead. There's simple ways to get the distinct count using this reference. After all it's like a field relation from one page to another and PW can use that in selectors to find pages matching a page in selected in a page field. But this can be done in different ways and direction depending on what you need this can make a big difference. Loop all values for a page field and filter then count pages that matches (maybe not ideal in your case), or loop all pages and collect and count the values of fields, kinda what we were doing above. And others. On the last one if you are using page fields, you somehow only need to know the ID of the page selected to be able to count (got it?), but its value(!) is, as we know it is a selected page (Page object), so you also need to know the field that makes the value, the one you usually output. This is usually the title, but can be also any other field on that selected pages. After all you could even have your fields array, you define previous to loop them through, specify the field name for the "value" this field is using as value. Uff, does this still make sense? I'm not sure how your setup is and how you'll go about to define what fields, so again just an example code. Assuming your page fields are all single value selects (they'd have to be for this to make sense). $somePages = $pages->find("template=child-templates, somefield=somevalue"); $fieldsArray = ("province" => "title", "network" => "count"); // "fieldname" => "fieldname_onselectedpage" $result = array(); foreach($fieldsArray as $field => $subfield){ foreach($somePages as $p) { if(isset($result[$field][$p->$field->$subfield])) $result[$field][$p->$field->$subfield]++; else $result[$field][$p->$field->$subfield] = 1; } } So $p->$field->$subfield would translate to $p->province->title $p->network->count Which is the selected page's "title" or for the network field "count" (maybe an integer field). Looping through all values of a field in your case, since those are pages would mean to maybe also loop values that are not used at all in those pages. So maybe not always desired depending on the pro and cons, and maybe also amount of pages you deal with. I think in this case just try and see what happens, there should be no very noticeable slowdown if you run this code until let's say 10 fields over 500 pages or 2-3 fields over 1000 pages. Hard to say out of the blue. If there's a lot more that need to be looped, I think you would need to consider some other direct sql queries ($db->query("SQLSTATEMENT"), $database->query("PDOSTATEMENT") On a sidenote I find it more and more very hard to commuicate such "complex" thing just for the terminology of all the things, like pages, selected pages, fields when having to deal with page arrays and page fields. I never know if the other person understands the same. Anyway.
-
It also depends if output formatting for the pages is on or off. If it's OFF a $page->field may be an object or array but when ON the same might be a string or a single object instead of an array. Good luck.
-
After all you can only fill an array with strings ro integers if you want to use array_count_values() later on. So if you deal with object or arrays for values you have to maybe (string) cast the value as you already found out. Then as Martijn points out the toString method comes into play and images or page arrays will end up like this as string: ["myimage1.jpg|someother.jpg"] or ["1203|1239|1233"] But then I don't know what suites in your case and what you really need, but you'll find out I'm sure.
-
No it's returning array with values, not a page. PageArray::explode() return array with the values of the requested properties of all pages in the page array. Maybe aswell look it up what it does, if explaining and showing it here isn't enough for you. https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/WireArray.php#L1423 Yes PageArray is an array with object, but I looks like you don't get it I'm looping page array. In there I loop fields array and fill an array with $array[$field][$p->$field] Translates to array["fieldnameA"]["value1"] -> count array["fieldnameA"]["value2"] -> count $p->$field is returning the value of the field. $field is a variable of the fieldname so it's like $p->fieldnameA But in your case it seems you deal with fields of type page so the field value is an object if you will so Filling array keys with objects or array leads to illegal offsets.
-
All my codes count distinct VALUES of those fields specified and not the field name. But you changed something there to $somePages->explode('name') and name would be the page names values, but you set them to the [$field] array so you mess things up. I don't see the need to add (string) as if you deal with strings there's no problem, but I guess you deal with objects or array as $p->$field and that's not allowed. After all I think you just need to adapt code to your needs and I provided various pseudo examples I think you can learn something. It's not meant to work for you as copy paste.
-
WireArray::explode() is not to count values but to create an array of PageArray, much like the php explode(), array_count_values() is the one only working with strings ans integers. WireArray::explode() doesn't care if it's a string or integer. Page fields or file fields, any multiple value fields are objects or arrays.
-
Well if you see this warning, then it's not a string or integer. It won't work with page fields, images fields etc.
-
The echo should be in "..." not '...'
-
Ah and just remembered that since PW 2.4 the simplest way to count values of certain keys/fields within a PageArray/WireArray is using the new WireAarray::explode() - combined with using PHP's array_count_values(array) you already used, it's down to this: $someFields = array("province", "network"); $somePages = $pages->find("template=child-template, category=xxx"); $resultArray = array(); foreach($someFields as $field) { $resultArray[$field] = array_count_values($somePages->explode($field)); } // that's it show array result foreach($resultArray as $field => $values) { foreach($values as $value => $count) { echo "<p>$field - $value: $count</p>"; } }
-
To get something as a function, just for learning purposes, the code could be like this function getDistinctValues(PageArray $pageArray, array $fields){ $arr = array(); foreach($pageArray as $p) foreach($fields as $field) if(isset($resultArray[$field][$p->$field])) $arr[$field][$p->$field]++; else $arr[$field][$p->$field] = 1; return $arr; } $someFields = array("title", "headline"); $somePages = $pages->find("template=basic-page"); $resultArray = getDistinctValues($somePages, $someFields); foreach($resultArray as $field => $values) foreach($values as $value => $count) echo "<p>$field - $value: $count</p>"; And following is a way to add a new method to a PageArray using a method hook. // this is right in a template code, but could also be in a autoload helper module wire()->addHook("PageArray::getDistinctValues", null, function(HookEvent $event){ $pageArray = $event->object; // the page array getDistinctValues($fieldsArr) is called on $fieldsArray = $event->arguments(0); // the first argument $arr = array(); foreach($pageArray as $p) foreach($fieldsArray as $field) if(isset($arr[$field][$p->$field])) $arr[$field][$p->$field]++; else $arr[$field][$p->$field] = 1; $event->return = $arr; }); $someFields = array("title", "headline"); // And now you can do this on a page find result $resultArray = $pages->find("template=child-template")->getDistinctValues($someFields); foreach($resultArray as $field => $values) foreach($values as $value => $count) echo "<p>$field - $value: $count</p>";