Jump to content

gRegor

Members
  • Posts

    119
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by gRegor

  1. First, I am running PW 2.4.12, so I realize this might be a beta bug that is fixable by me upgrading, but I'm following examples that have been around for a while, so I figured I would ask. I am following the wiki's example for making a configurable module and it creates the fields properly, but is not storing the default values on install. In the __construct() method I have tried both variants: # variant 1 $this->foo = 'value'; # variant 2 $this->set('foo', 'value'); And then my getModuleConfigInputFields(array $data) method has: $inputfields = new InputfieldWrapper(); $field = wire('modules')->get('InputfieldText'); $field->name = 'foo'; $field->label = 'Label for foo'; if ( isset($data['foo']) ) { $field->value = $data['foo']; } $inputfields->add($field); return $inputfields; After install, the module shows the field, but its value is blank. I've confirmed the 'data' field in the modules table is blank, too. At this point, I can enter a value, click submit, and the 'data' field is updated and reflects in the form. Is there an additional method call needed in my __install() to trigger storing these default values?
  2. I would check if any pages are still using the template and only remove it if it was zero. I might make it a config option to have the module remove its pages on uninstall, though.
  3. I am working on a module that will require a template and certain set of fields. I was wondering what the best practices are to achieve this. I have used soma's Images Manager module and I noticed it requires you to manually create some fields, templates, and pages. The current route I am considering is: Set the module up with ConfigurableModule and several options for the default field/template names. IF: the template and field names do not already exist:​Create the templates and fields, indicate install is completed successfully ​ELSE:Prompt the user to create the templates/fields manually and enter the names in the module's configuration. Alternately, I suppose the install method could take the base name for fields/templates and add an incremented number to the end until a unique name is found. This might be preferable since it would not require any manual configuration. Thoughts?
  4. An alternative that I just implemented: I set up field 'bootstrap_column' as a Repeater, with fields 'bootsrap_column_span' and 'body'. 'bootstrap_column_span' is an integer field with value range 1-12. Then I loop through the bootstrap_column field and keep track of the column spans, creating new rows as necessary: echo '<div class="row">'; $i = 0; foreach ( $page->bootstrap_column as $column ) { $i += $column->bootstrap_column_span; # if: over 12 columns; start a new row if ( $i > 12 ) { $i = $column->bootstrap_column_span; echo '</div> <!--/.row -->'; echo '<div class="row">'; } # end if echo sprintf('<div class="span%d"> %s </div>', $column->bootstrap_column_span, $column->body ); } # end loop echo '</div> <!--/.row -->'; It may not be the most efficient method and the repeater field doesn't reflect how it will look on the front end, but I think it will work for my needs so far. I actually didn't look into PageTable or setting up sub-pages for different sections of content. Edit: just realized I missed the conditions when the column span is exactly 12. I will need to add that.
  5. Thanks, horst and ryan. Wow, that's a really smooth process. I like the auto DB/htaccess updates. PW continually impresses me! Is there a way to tell what version the dev branch is at? I don't see tags for the minor version numbers. I guess it doesn't matter for the upgrade process; just curious.
  6. In early August I installed the dev branch of ProcessWire 2.5. I'd like to upgrade to the latest dev version. Does that entail just uploading the latest version of the files, then checking the install.sql file and making changes to the database manually? Unfortunately, I did not make note of which Git commit it was I installed from, though I could probably narrow it down to the date. The footer reports v2.4.10, but I don't think that's correct? Thanks for any help. I'm new to running dev versions of PW.
  7. $var = (int) NULL; Will result in zero, unless there is some weird PHP setup I'm not aware of.
  8. Currently, I have chosen to set up a module based on the Auto Paragraph module linked above, except it's a general-use module that I load on demand and pass the text into. It seems to work well. I'd still appreciate feedback if there is an easier / preferred method for doing this, though. Thanks!
  9. Personally, I'd prefer casting it explicitly to an integer. That way if it's empty, it will become a zero. Also, since you set the average flying time to a shorter variable, might as well re-use it. $farflung = ''; $airport = $page->DMC_select->DMCstats_Airports->first(); $flying_time = (int) $page->DMC_select->DMC_Average_Flying_Time_hours; if ( $flying_time > 1 ) { $plural = 's'; } if ( $flying_time > 0 && $flying_time < 6 ) { $flying_message .= "With the average flight from a UK airport to {$airport->title} ({$country}) at just {$flying_time} hour{$plural} this is an ideal short haul destination."; } else { $farflung = "far flung {$flying_time}"; }
  10. Hello, I have built a form that allows authenticated members to submit articles through a front-end form. I was under the impression that 2 newlines would automatically be converted to paragraph elements, but I'm pretty sure that's incorrect as I re-acquaint myself with this aspect of PW.** Then I was thinking there was a TinyMCE configuration to convert newlines to paragraphs. There is, but I'm pretty sure that applies only during entry into the textarea, not when the text data is first loaded into the TinyMCE textarea. First, is there a built-in PW paragraph formatting function that I'm missing/forgetting? If not, would the "preferred" method to achieve this be using TinyMCE on the front-end form, so newlines are converted to paragraphs before the form is submitted and the page fields are stored? If so, can someone point me to an example of using the PW API to include a TinyMCE field input? Or would the preferred method be to process the raw input to convert newlines to paragraphs (through another module, or custom code) before saving the page fields? I'm aware there is an Auto Paragraph TextFormatter module, but I believe that only applies when the data is output — not when the data is shown in backend. Thanks for any assistance! ** I have confirmed that the newlines are stored in the database, so I've confirmed they're neither being removed nor converted.
  11. For the sake of time (I need to get this form set up rather quickly), I'm doing something similar to Soma's code here: https://gist.github.com/somatonic/5233338 I'm still curious if there's a method to achieve what I want without additional code to process the fields - using mostly native API methods, that is. Please let me know any suggestions.
  12. Thanks, adrian. That actually adds to the error message array, so both messages appear, which is undesirable. I had experimented with that a bit previously. My form is set up in the same way as soma's first post in that thread, using the render() method to display the form after building all the fields via the API.
  13. Hi, all. I've read through most of soma's thread "Create simple forms using API" and think I understand the basics pretty well. I fall in love more and more with Processwire each day. First, I am wondering if it's possible to not display the error messages inline, with each form field, and instead show a list of errors at the top of the form. The typical UI I use for form error messages is "Please fix the following errors and re-submit the form" followed by an unordered list of the error messages. I see that the getErrors() method returns an array of the field names and error messages, so that is simple enough. I'm not sure how to turn off the error messages that display with each form field, though. Secondly, I am wondering if it's possible to customize the error message for each field, via the API. I understand the text can be internationalized, but I am looking for more specific messages like "Please enter your First Name" instead of "First Name: Missing required value." Thanks for any help!
  14. Thanks, onjegolders! I was not aware of that. I'd searched the API and forums a bit, but had not looked at modules yet.
  15. Hello, I am trying to set up a multi-level menu in nested unordered lists. Specifically, I want to get pages from the first three levels in the page hierarchy. Since the page structure is somewhat complex and I wanted it to be flexible in the future, I added a checkbox field named "in_main_menu" that I can then use as a selector, in case some pages should not appear in the menu. The top level menu was easy: $main_menu = $pages->find('parent=/, in_main_menu=1, sort=sort, limit=7'); Then, as I was thinking through how to set up the nested navigation under each main menu item, I was thinking a "maximum depth" selector would be handy. Return all pages matching this selector that are no more than 3 levels deep in the hierarchy. I could not find a way to do that with selectors, though. I believe such a method would not return the pages in the exact order I want, anyway. My next thought was that I can just perform a find that returns all pages with in_main_menu, then process the results and build an array in the desired format. I'm not totally sure how that processing would work; I think it would be a bit complicated. Rather than dive into that . . . my final attempt (before posting now ) was to loop through the main menu pages and call children() on each of those. Then repeat for the third level. This seems to work, except for the third level, where I get an error. # loop: main menu pages foreach ( $main_menu as $main ) { // output top-level menu item # if: secondary menu if ( $secondary_menu = $main->children('in_main_menu=1') ) { # loop: secondary menu pages foreach ( $secondary_menu as $second ) { // output second-level menu item # if: tertiary menu if ( $tertiary_menu = $second->children('in_main_menu=1') ) { # loop: tertiary menu pages foreach ( $tertiary_menu as $third ) { // output third-level menu item } # end loop: tertiary menu pages } # end if: tertiary menu } # end loop: secondary menu pages } # end if: secondary menu } # end loop: main menu pages And it looks like this will work! My question, though, is whether I'm overlooking a simpler method. I would welcome your feedback. I realize I could abstract my code into a function (that would also allow N-levels), but I'm curious if there's even easier ways with the PW API.
×
×
  • Create New...