Jump to content

cosmicsafari

Members
  • Posts

    80
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

cosmicsafari's Achievements

Full Member

Full Member (4/6)

13

Reputation

  1. Hi all, So I ended up editing the snippet to the following which got me around the null error I was encountering. Figured i'd paste this for anybody else looking for something similar in the future. <?php /** @var InputfieldMarkup $f */ $f = $this->wire->modules->get('InputfieldMarkup'); $f->set('label', 'Development Template Ordering'); $markup = '<ul>'; $blocks = processwire\wire('pages')->get('template=development_template_ordering_settings')->development_template_ordering; foreach($blocks as $block){ $markup .= '<li>'.$block->title.'</li>'; } $markup .= '</ul>'; echo $markup; ?>
  2. Ah this looks like its exactly what im looking for. 😃 Can I just ask, did you get that code to work in order to take that screenshot, as I am getting a null error on the last line. Just curious of your field settings for the runtime fieldtype in this instance incase I need to ammend mine to get the same result.
  3. Hi all, I have what on the face of it what seems like a simple addition I want to add to a template, but im a bit stumped in how to achieve it. Basically I have a global page reference field that allows a user to order the output of a given template file. So this global field sits on its own template/page, and on it you can just order a list of named items, nothing fancy. Now I can use this order the front end no problem by just using the field name and a foreach loop. But I have no idea if that same output is possible within a different page/template within the cms. All I am wanting to do on this other template file is just output the content of the global field, just so that anyone on a page using the second template has the current global order for reference. Nothing fancy, doesn't have to do anything just display a list of items in the order set on the global settings page. I figured this would be fairly simple to do, as I have setup many textual type outputs for backend module configs however in this instance im not sure what I need to do to get similar output within the cms page using said template. I had thought hanna code might be useable but I can't see anyway to get it to execute from within the cms, albeit the page where you can set up the php snippet does do exactly that when you test it. Any ideas on how I could achieve the above? Screen shots of what im trying to explain incase it helps any. (Global settings ordering screenshot) (My attempts at outputting the above, on another cms page with Hannacode, where [[test]] is a snippet that just loops over the above and outputs it in a <li>) So is it possble to have the output appear there, as in execute the hannacode snippet [[test]] and show me the output like it would do on the frontend? Any advice would be much apprecriated.
  4. Hi all, Not sure if this is the correct place for this question but as it pertains to the Image Marker module, I thought this might make sense. For some context, we had been using the module with a few custom changes for a couple years at this point. However for our needs we had to remove the int casting within the code, and updated the DB columns for the X & Y coordinates to be more precise. This was working fine up until recently when we noticed that the pins where moving slightly after having been positioned and then saved. The only thing we have changed in that time was upgrading the WP Core, and im curious if anyone is aware of any changes that would effect the rounding in this scenario? I could be wrong but from, sticking in a bunch of custom logging, I was able to follow the process to see at which point the rounding is occuring. If im understanding things correctly, it looks its occuring between sleepValue() and wakeupValue() based on this logging output. I have looked through the module files and can find no more instances of int casting or rounding, so im at the point now where im wondering if its actually the updated core thats contributting to this rounding, as sleepValue and wakeupValue are extendable if I understand things correctly, so presumably theres some element of the core coming into play with them? I should also mention, that I have tried changing the DB columns to use DECIMAL, FLOAT & DOUBLE datatypes but all result in the same odd rounding down to the nearest whole number. I'm convinced its not mysql doing the rounding, as I can manually enter the values no problem using Sequel Pro, but it always rounds down when saved via the CMS. Any thoughts or ideas would be much appreciated.
  5. Hi all, Just wondering if anyone else has encountered this issue. During some work recently I have noticed that it seems like when you use count() on a repeating field to determine if theres any content to output, it works fine on a template but behind the scenes as part of a module it doesn't return the same results on the same data set. For instance. On the frontend template this outputs as you would imagine: Doing a count on that same field, from within a module I get count() returning as 2, which makes sense as both are enabled. However I noticed that, if I then disable one of the repeating items, ala: This is reflected in the frontend as you would imagine, like so: However within the module logic, the value of count() on the same data set will still return as 2 The fact that I can't rely on the count within the module being correct is having major knock on effects as I have no idea whether to trust any information brought back about that repeating field. Does anyone know a way to get a correct number from a repeating_field->count or count(repeating_field) from the API, that actually takes into account the enable/disabled status of the elements within it? I have tried using various methods which are fine on a page template but just seem unreliable in my modules context, for some clarity, this is how I am pulling out the same field via the module: $overrides = $this->pages->findOne("template=plot, parent.id="666", title=plot 101"); then the following to check if there any content within the repeater error_log('COUNT:'.count($overrides->key_features)); For the record the following also appears to be giving the same as above error_log('COUNT:'.$overrides->key_features->count); So presumably this is a bug or COUNT() works diffferently between use in templates and usage with the API? If its working as intended, can anyone point me towards some documentation that explains the differences? Any thoughts would be much appreciated?
  6. Hi all, Just a little context, I have need of a select/drop down on a form to update automatically. So I believed I had achieved this, by programmatically updating said field via an webhook, code included below. Which looked like it worked, as all the correct options do now infact show in the drop down on page load.... However, whenever I select one of these newly added options on the drop down and hit submit, it always throws an error as if the field has infact been left blank? Out of curiosity I removed the 'Required' settings from the field, which when I tested does allow me to select a development and then submit without the error, however if you then check the entries tab within Formbuilder that field is just left blank? I also removed the webhook for dynamic population wherein the field on the form started behaving normally again, so presumably something below is causing the problem? Any ideas? $wire->addHookBefore('InputfieldSelect::render', function($event) { $inputfield = $event->object; if($inputfield->name != 'priority_development') return; $options = $inputfield->options; // Get the existing options //GET CURRENT PUBLISHED DEVELOPMENTS $options_new = []; $pages = Processwire\wire('pages')->find('template=development'); foreach($pages as $page){ $region = $page->development_region->title; $options_new[$page->id] = $region.', '.$page->title; } asort($options_new); $inputfield->options = []; // Remove all the existing options // Add the options back with attributes $inc = 0; foreach($options_new as $value => $label) { // Set whatever attributes you want as $key => $value in the last argument of addOption() if($inc == 0) { $inputfield->addOption($value, $label, array('selected' => 'selected')); } else { $inputfield->addOption($value, $label); } $inc++; } $event->return = $inputfield; });
  7. Hi all, For some context, I have some pages which get updated using the PW API at regular intervals via some scheduled tasks. I recently installed the Activity Monitor module which worked great for manual updates to those pages, however it would never track changes made via the API. Anyway because of this I started looking around for something that would track API changes, but thus far haven't came across anything. However I did notice this page: https://processwire.com/api/ref/page/track-changes/ Apologies if this is a daft question, but the content on that page makes it seem like tracking changes is already native to PW and just needs enabled? Is this correct? As in could I update my scripts that use the API to enable the changes to be tracked at the point of page saving? Also if anyone does know of any modules that would track API changes to save me having to code my own solution could you please throw them my way as it would be much appreciated.
  8. Hi all, This is likely a really stupid question, but how do I go about enabling the result descriptions and text highlighting? I have seen @teppo mention it and have seen theres methods in the codebase relating to it but for the life of me I can't figure out how to enable it. My search results are only returning a page title and a url at present, which I figured was the out the box default but not 100% sure.
  9. Hi all, Before I go potentially wasting time trying to achieve the impossible. Can anyone confirm if its possible to have a Page Reference field on a modules config page? I'm wanting to essentially just output a list of select able pages based on the a given selector (likely by template at this stage), wherein the select is the pages that the module should apply to etc. I was thinking a simple checkbox list would suffice is asmSelect isn't available. Essentially have it display the same way a Page Reference field would display on a template, where you can easily select a bunch of them. public function getInputfields() { $inputfields = parent::getInputfields(); $f = $this->modules->get('InputfieldPage'); $f->attr('name', 'testSelect'); $f->setAttribute('multiple', 'checkboxes'); $f->setAttribute('findPagesSelector', 'template=development'); $f->label = 'Test'; $inputfields->add($f); return $inputfields; } Figured something akin to the above would work but can't seem to get rid of this warning on the modules config screen though.
  10. Not sure why the embed version didn't work but I changed it to render and it started working. That said according to here it looks like the original should have worked also? https://processwire.com/api/ref/form-builder/embed/ <?php echo $forms->render ('my-form-name', array('hidden_field_name' => '666')); ?>
  11. Hi all, I have the same form on multiple pages, the idea being that I can populated a hidden field with a page specific value automatically. I figured this should be reasonably straight forward but I can't seem to get the following to take effect. <?php echo $forms->embed ('my-form-name', array('hidden_field_name' => '666')); ?> No matter what I do, it never updates the default value currently set for said hidden field. Feels like I'm missing something really obvious? Any ideas?
  12. Ok well that would explain that then, any particular reason why out of curiosity?
  13. Hi all, I have need to dynamically set InputFieldMultiSelect to selected on page load based on the status of some items within a database table. However I keep running into issues when trying to do this via InputfieldSelect::setOptionAttributes() https://processwire.com/api/ref/inputfield-select/set-option-attributes/ Going by the above it sounds like it should be pretty straight forward, and for certain values it seems to work but not when I wanted to set it to 'selected'. For example: $f->setOptionAttributes(1030,['foo' => 'test']); The above works as I would have wanted, in that it updates the option with the value 1030, to include the attribute foo="test" But the same code above edited to the following: $f->setOptionAttributes(1030,['selected' => 'selected']); Doesn't seem to do anything? I assume I'm missing something or trying to implement the 'selected' wrongly but I'm not sure how else I should approach this, any advice would be much appreciated.
  14. Thank you for the suggestions. I did have a look at the content within the BCE module but found it hard to follow. Its a fantastic module but its far more advanced than anything I have ever put together but I will continue to look into it. Apologies I should have mentioned it does work with a small enough CSV file. However I will make some changes and see how I get on. I'm not sure if its relevant but the storage engine of the database is InnoDB.
  15. Hi all, Just looking for some advice. I have created an admin page where the user can upload a fairly simple csv, in order to create a bunch of pages in batch. I have recently been trying to update it so that it wipes the existing pages created by the last upload before creating new pages based on the newly uploaded CSV. I'm obviously missing something as any CSV or indeed any attempt to batch import/delete always results in a 504 Timeout. Figured this was just something we would just have to work around and likely due to server constraints. However I recently installed the Batch Child Editor module (http://modules.processwire.com/modules/batch-child-editor) out of curiosity. Anyway too my point, I can use this module to delete the same number or indeed import the same number of items that my implementation struggles to cope with. So I was hoping if I posted a snippet of my own simple version, I could get some pointers as to where we think the bottleneck is as im clearly doing something wrong. Any thoughts and advice are welcome. <?php if ( isset($_POST["submit"]) ) { if ( isset($_FILES["file"])) { //if there was an error uploading the file if ($_FILES["file"]["error"] > 0) { echo "Error Uploading File (Return Code: " . $_FILES["file"]["error"] . ")<br />"; } else { $created = 0; //if file already exists if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { //Store file in directory "upload" with the name of "uploaded_file.txt" $storagename = "../assets/csv/uploaded_file.txt"; move_uploaded_file($_FILES["file"]["tmp_name"], $storagename); if(($handle = fopen($storagename, 'r')) !== false) { // get the first row, which contains the column-titles (if necessary) $header = fgetcsv($handle); $x=0; $group_settings = wire('pages')->get('name="group-settings"'); // loop through the file line-by-line while(($data = fgetcsv($handle)) !== false) { $lng = $data[0]; $lat = $data[1]; $name = $data[2]; $contact = $data[3]; $email = $data[4]; $phone = $data[5]; //CREATE error_log('('.$name.') CREATE'); $p = new Processwire\Page(); $p->template = 'group'; $p->name = $name.'('.$lat.','.$lng.')'; $p->title = $name.'('.$lat.','.$lng.')'; $p->parent = $group_settings; $p->text_a = $name; $p->text_b = $contact; $p->group_location->lat = $lat; $p->group_location->lng = $lng; $p->email = $email; $p->phone_number = $phone; $p->save(); $created++; unset($data); } fclose($handle); } } } } else if ( isset($_REQUEST["delete"]) ) { //Delete existing locations $p = $pages->get('/settings/group-settings/'); foreach($p->children as $child){ $child->delete(); } } else { echo "No file selected <br />"; } } ?>
×
×
  • Create New...