pogidude
Members-
Posts
122 -
Joined
-
Last visited
Everything posted by pogidude
-
What you'll probably want to do is: 1. Find all pages whose date_field is not empty but whose date_field is past $today. $what_you_dont_want = $this->pages->find("date_field>0, date_field<$today"); 2. now select what you want $what_you_want = $this->pages->find("template=template_with_date_field, id!=$what_you_dont_want, limit=$limit"); The general idea is: 1. Find all pages that you want to exclude. 2. Find ALL the pages but filter out the pages found in #1. Thoughts: You can use filter() method for this by finding all the pages you need first then filtering out what you don't want but this somehow messes up pagination by default as what I mentioned in the original post. BUT, ryan did say you can use setTotal() and setLimit() methods on the PageArray but I haven't tried it since I'd already found a solution but then was too lazy to rewrite
-
Use existing field but change label and description
pogidude replied to pogidude's topic in API & Templates
Thanks for pointing me in the right direction Ryan. Although it took a bit of figuring tinkering around since I initially got this error "Field must be in fieldgroup context before its context can be saved" for those passing through this thread, finally got the following code working correctly: //add the field to the template first $mytemplate = wire('templates')->get('mytemplate'); $mytemplate->fieldgroup-add('roles'); $mytemplate->fieldgroup->save(); //-- we now *override* the default label and description to suit our template --// $field = $mytemplate->fieldgroup->getField('roles', true); //!IMPORTANT: set 2nd parameter to true to get the field in the context of the fieldgroup. //note: I don't really understand what "in the context of.." means though $field->label = 'Select roles'; $field->description = 'Select the roles that should receive notifications.'; //now save! wire('fields')->saveFieldgroupContext($field, $template->fieldgroup); For those who want to go through core, the hints are in wire/modules/Process/ProcessField/ProcessField.module -
I'd like to add an existing field to a template via api but I'd like to change some attributes first. Equivalent action is if I were using gui, I would edit the template and in the list of fields (asmselect) I'd click on the field which would trigger a modal window where I can then edit the field's label and description. How do I do that using api?
-
hmmm.. not *all* fields are uncached as the uncache() method is only triggered on fields that reference objects. and not sure but the uncaching seems to be done by the field value and not the field itself.. I dunno.. and since text fields are just text and can't call uncache... they don't get reloaded from the db? which is why after uncaching a page, changes to text fields still get saved while object fields don't? also in Page::uncache() I'm wondering why the value is set to null: if($value != null && is_object($value)) { if(method_exists($value, 'uncache')) $value->uncache(); parent::set($field->name, null); } SIDENOTE: I'm very interested in the inner workings of PW as I'm trying to create a small version of it as a framework for wordpress plugins.
-
but still it would be nice to know why formatted fields aren't getting saved while other fields are saved. Not really a biggie but it sort of stands out for me in ProcessWire which has a really really clean and consistent interface (that I wish other frameworks would emulate) that stuff like this tend to stick out
-
thanks Soma. Yup got it working with this: $page = $event->arguments('page'); $clone = clone($page); $clone->uncache(); $this->pageStatusBeforeSave = $clone->myfield;
-
One gotcha if you uncache a page as I've done it is that *some* of the fields don't save. Which is kind of weird behaviour to me because I'd at least expect either ALL or NONE of the fields to be saved if I call uncache() on the current page. Specifically, all the text type fields get saved i.e. textarea, text (as in title, body) but the field types that don't get saved are FieldtypeTemplates and FieldtypePage fields. what gives? anyhow, I ended up doing this to get the value stored in the database: $clone = $page; $clone->uncache(); $this->pageStatusBeforeSave = $clone->myfield;
-
In my module, I'm hooking into Pages::saveReady and have the following code: // get the old value of the field $this->pages->uncache($page); $page = $this->pages->get($page->id); $this->pageStatusBeforeSave = $page->$statusFieldName; basically, I'm trying to get the *database-stored* value of the field and not the *soon-to-be-saved* one which seems to be the case if I don't call uncache(). So, what I'm really asking is, will uncaching the page have other effects that I don't see? And yes, I've already seen this http://processwire.com/talk/topic/2593-tracking-changes-on-pages-%E2%80%93-getting-original-value/ and this http://processwire.com/talk/topic/1067-accessing-previous-version-of-page-beforeafter-page-save/#entry9321 and have already studied Netcarver's field change notifier module very nice by the way
-
Actually, it's a warning I'm getting PHP Warning: Invalid argument supplied for foreach() in /srv/www/ssd.pw/html/site/modules/FieldtypeTemplates.module on line 96, referer: http://ssd.pw/admin/page/ so the problem only shows up if I have $config->debug = true. And this only happens when the Templates Select Field hasn't been set yet and I'm calling the field in my code already like this: if(count($page->templates_field)){ ....
-
So, I added a FieldtypeTemplates to my template and set data to it like so: if(isset($_POST['templates'])){ //comma separated list of template ids $templates = explode(',', $_POST['templates']); } $mypage->the_templates_field = $templates; $mypage->save(); and this resulted in an unset templates select field - like the field was newly added. Took me awhile to figure it out but in FieldtypeTemplates::sanitizeValue() line #43: foreach ($value as $k => $v) { // we allow integers if (is_int($v) && $this->templates->get($v)) continue; // we allow templates if ($v instanceof Template) continue; // but we don't allow anything else unset($value[$k]); } I changed is_int($v) to is_numeric($v) as noted here http://php.net/manual/en/function.is-int.php and got the desired behaviour.
-
wow! works! weird though coz admin template has "allow page numbers" checked and not urlsegments. and yes, I had the "process" field on the custom admin template and it was working just fine - as long as you set alternate template to "admin" - except for the urlsegments thing. anyway, thanks for pointing me in the right direction
-
The module does extend process https://github.com/ryannmicua/ProcessContentFlow/blob/master/ProcessContentFlow.module#L86 and that is the test urlsegment i'm trying. Just a thought though, would it matter if my process page doesn't exactly use 'admin' template? I have a different template in use and setting "admin" only as alternate template.
-
I'm getting this warning due to my usage of FieldtypeTemplates in my module: PHP Warning: Invalid argument supplied for foreach() in /srv/www/ssd.pw/html/site/modules/FieldtypeTemplates.module on line 96, referer: http://ssd.pw/admin/page/ Unfortunately, if $config->debug = true, then, when I go to http://ssd.pw/admin/page/ (which lists the page tree), all I get is the right arrow and now tree. Here is the module I'm working on https://github.com/ryannmicua/ProcessContentFlow and this is the part where I'm calling the templates fieldtype https://github.com/ryannmicua/ProcessContentFlow/blob/master/PageContentFlow.module#L61 EDIT: This is how I'm using the field in my module: if(count($page->template_field)){ .... EDIT_END The warning only appears if I haven't selected any template in the inputfield yet - like right after putting the template field to a fieldgroup and this field hasn't been set yet. As a temporary fix, I added the following code on top of the code in FieldtypeTemplates::___formatValue() if(empty($value)) return $this->getBlankValue($page, $field); By the way, why no github?
-
Just figured out something today which I think is pretty cool (at least I thought so since I haven't found this in any docs), although I'm still trying to figure out how to make it work for my module. As an example, under admin/setup/template/, when you add the text "add" to your url - admin/setup/template/add - in ProcessTemplate, the executeAdd() method is called. When you type "edit" instead, the executeEdit() method is run instead. I'm just wondering how this works. I tried creating a similar method in my module - executeTest() with some dummy inputfields and I got a 404 error instead. I'm trying to add a "this is what's going to happen if you set this option" page - like what happens when you change templates in the page or when you remove a field from a template.
-
thanks ryan. by the way, where is this array value (or object) checked in core? I'm trying to get an idea of the path of calls that happen when you save a field value.
-
what does echo $variable1 || $variable2 mean?
pogidude replied to pogidude's topic in General Support
sweet.. thanks for clarifying.. I so suck at this.. lol. -
what does echo $variable1 || $variable2 mean?
pogidude replied to pogidude's topic in General Support
I know.. I'm just making sure that the echo part isn't needed for the call to copy() - which I don't think is, but just want to make sure -
Just like the title says, what does this mean? // Copy the admin.php template over the old one echo wire('config')->paths->siteModules . 'ProcessAdminCustomPages/admin.php' . '||' . wire('config')->paths->templates . 'admin.php'; //exit; copy ( wire('config')->paths->siteModules . 'ProcessAdminCustomPages/admin.php', wire('config')->paths->templates . 'admin.php'); got this from ProcessAdminCustomPages module. I understand the copy() part. I'm not sure what the echo part is for.
-
thanks Soma. yeah, actually I already did try, I wanted to hook to Pages::saved() and had typed Page::saved() instead, which led to a lot of head banging..
-
How do I hook into a protected method from my module? Example, Pages::saved(). This is defined as: protected function ___saved(Page $page) { } This is how my module is implemented: class PageContentFlow extends WireData implements Module{ .... } is it possible?
-
Hi, I got the same problem as Raul. Was just about to create my own thread with this same issue when I chanced across Raul's post. I'm using version 2.3 dev version.. to duplicate the issue: 1. Create a new field with type "Templates" 2. Add the field to a page. 3. Edit the page and select some templates. 4. Save the page. 5. Now, unselect all the templates. 6. Save the page. You should see the templates get selected back again. You can unselect the templates and remove all but one. that's also the issue that Raul described above.
-
(slap head) I totally forgot it was a NOT (!) conditional.. now I get it.. thanks!
-
thanks for the answer wanze. though I still don't get why you need this check in ProcessPageEdit::init(). I mean, what if you're just loading a page for editing? you know, not yet clicked on the "save" buttons.
-
In ProcessPageEdit::init() method, there is this line of code at the bottom which loads JqueryWireTabs module: if(!$this->isPost) $this->modules->get('JqueryWireTabs'); my question is, what does $this->isPost mean? when is this value true? or false?
-
Thank you Wanze and thank you Ryan Yes, I did notice that "add()" and "append()" both resulted in the same thing so I wanted to make sure that there was no implementation difference between the two