Jump to content

Robin S

Members
  • Posts

    4,928
  • Joined

  • Days Won

    321

Everything posted by Robin S

  1. @jonassalen, open the ProcessSetupPageName.module file in your code editor and try replacing this section at the top of the createFromFormat() method... if ($languageID == null && $this->languageSupport == true) $languageID = $this->wire('languages')->getDefault()->id; $langID = $this->wire('languages')->get($languageID)->isDefault()? null : $languageID; if ($this->languageSupport) { $userLang = $this->wire('user')->language; $this->wire('user')->language = $this->wire('languages')->get($languageID); } ...with... $langID = null; if ($this->languageSupport) { if ($languageID == null) $languageID = $this->wire('languages')->getDefault()->id; $langID = $this->wire('languages')->get($languageID)->isDefault()? null : $languageID; $userLang = $this->wire('user')->language; $this->wire('user')->language = $this->wire('languages')->get($languageID); }
  2. See ProcessWire::getHttpHost(). If PW cannot match a host in your $config->httpHosts array from PHP's predefined $_SERVER variable then it gives you the first item from $config->httpHosts.
  3. @horst, I have implemented your request in v0.1.1 as a separate autocomplete on the "Add Module From URL" field. See the updated readme for details.
  4. A recent answer to a similar question:
  5. That's because ultimately the references depend on the execution of the FieldtypePage::findReferences() method. This method has to be called for each page you want to get or count the references to. And so the number of references is not a simple value in the database that you can query in a $pages->find() selector the way a field value is. Enabling selectors that query or sort by the number of references is one of the motivations behind the Connect Page Fields module. If you use this module to create a two-way relationship between Page Reference fields then it's easy to write the selector you want. Note that you can set the visibility of a Page Reference field to hidden if you don't need to see it in Page Edit but only want to query it in selectors.
  6. After forgetting the class name of the wonderful AdminPageFieldEditLinks module for what feels like the 100th time I decided I needed to give my failing memory a helping hand... Autocomplete Module Class Name Provides class name autocomplete suggestions for the "Add Module From Directory" and "Add Module From URL" fields at Modules > New. Requires ProcessWire >= v3.0.16. Screencast Installation Install the Autocomplete Module Class Name module. Configuration Add Module From Directory Choose the type of autocomplete suggestions list: "Module class names from directory" or "Custom list of module class names". The latter could be useful if you regularly install some modules and would prefer a shorter list of autocomplete suggestions. The list of class names in the modules directory is generated when the Autocomplete Module Class Name module is installed. It doesn't update automatically (because the retrieval of the class names is quite slow), but you can use the button underneath when you want to retrieve an updated list of class names from the directory. Add Module From URL If you want to see autocomplete suggestions for the "Add Module From URL" field then enter them in the following format: [autocomplete suggestion] > [module ZIP url] Example: RepeaterImages > https://github.com/Toutouwai/RepeaterImages/archive/master.zip Awesomplete options The "fuzzy search" option uses custom filter and item functions for Awesomplete so that the characters you type just have to exist in the autocomplete suggestion item and occur after preceding matches but do not need to be contiguous. Uncheck this option if you prefer the standard Awesomplete matching. Custom settings for Awesomplete can be entered in the "Awesomplete options" field if needed. See the Awesomplete documentation for more information. https://github.com/Toutouwai/AutocompleteModuleClassName https://modules.processwire.com/modules/autocomplete-module-class-name/
  7. Anything that can be done with the API can be turned into an executable action with @adrian's Admin Actions module. And you can make an action available to non-superusers too. There's a built-in "Copy Field Content to Other Page" action that you can use as a starting point. This action doesn't work out-of-the-box for Files or Images fields but it wouldn't be difficult to get it working, especially now that you can use Pagefiles::add() with a Pagefile object so that descriptions and tags get copied over automatically. And if you update the action maybe submit a pull request to the module repo with your changes...?
  8. @tpr, would you consider adding an exclude class to the "Autosize textareas according to content" feature? Generally I like this feature but I have some modules with textareas in their config that contain a lot of content and would like to be able to exclude these from being autosized. So I was thinking there could be some special class that can be applied to textareas (e.g. "no-autosize") and the AOS feature when enabled would apply to all textareas without this class. What do you think?
  9. @stuartsa, you can achieve a step setting for InputfieldInteger / InputfieldFloat / InputfieldDecimal by a couple of hooks in /site/ready.php: // Add a step setting to InputfieldInteger / InputfieldFloat / InputfieldDecimal $wire->addHookAfter('Inputfield(className=InputfieldInteger|InputfieldFloat|InputfieldDecimal)::getConfigInputfields', function(HookEvent $event) { $inputfield = $event->object; $field = $inputfield->hasField; if(!$field) return; /* @var InputfieldWrapper $wrapper */ $wrapper = $event->return; /* @var InputfieldText $f */ $f = $event->wire('modules')->InputfieldText; $f->name = 'step'; $f->label = 'Step'; $f->value = $field->step; $f->showIf = 'inputType=number'; $wrapper->add($f); }); // Add step attribute to InputfieldInteger / InputfieldFloat / InputfieldDecimal $wire->addHookBefore('Inputfield(className=InputfieldInteger|InputfieldFloat|InputfieldDecimal)::render', function(HookEvent $event) { /* @var Inputfield $inputfield */ $inputfield = $event->object; $field = $inputfield->hasField; if(!$field || !$field->step || $field->inputType !== 'number') return; $inputfield->attr('step', $field->step); });
  10. This would only be useful for simple, single-value fields like text fields, right? Because how would it work with an Images field or a Repeater field for example? Anyway, here is a proof-of-concept FileCompiler module: https://github.com/Toutouwai/FileCompilerDataAttributes File Compiler Data Attributes A proof of concept module for populating markup elements according to data attributes containing a field name. Created in response to this forum topic. This approach is really only useful for simple, single-value fields such as text fields as far as I can see. Installation Install the File Compiler Data Attributes module. Setup If you follow the practice of starting your template files with the ProcessWire namespace declaration then for every template you want to use this module with you must change the "Use Compiled File?" option in the template settings from the default option. You must choose either of the "Yes" options depending on what suits you best. I find the need to do this annoying and there is an open issue about it. There is an option in the module config to strip the data-field attribute from the markup when the template file is compiled. Usage In your template files, insert HTML elements (probably empty elements although this is not compulsory) with a data-fieldattribute set according the field name you want to populate the element from. Example: <h1 data-field="title"></h1> <div data-field="body"></div>
  11. @stanoliver, yes, I understand the objective. What's not clear is how your blog posts are identified as belonging to a particular category. If there is a blog post titled "My bike" and it is in the category of "bike", how do you connect category "bike" with post "My bike"? Probably it would help if you show a screenshot of your page tree, with both the post pages visible and the category pages visible. Most commonly, developers structure their website so that they have a structure of category pages (using template "category" let's say), and then they have a Page Reference field (named "categories" let's say, with selectable pages "template=category") and they add this Page Reference field to the post template. Then for each post they select one or more category pages. That's what my previous post assumes. So that when you are viewing a category page on the front-end, that category page exists as the $page variable. And so if you want to find posts that have that category page assigned to them you search for them with this: $results = $pages->find("template=templateblogpost, categories=$page, limit=5, sort=-postdate"); Another way that you might be connecting categories to posts is by a parent-child relationship. So the post pages are children of a category page that they belong to. This is okay but less flexible because it means that any post can only belong to one category. So if you found yourself needing to write a blog post "How to fix a bike rack to your car" you would have a problem because the post could only be in the bike category or the car category but not both. But if you are in fact using a parent-child relationship you would use this selector on the category page (note change from $pages->find to $page->children): $results = $page->children("template=templateblogpost, limit=5, sort=-postdate");
  12. @stanoliver, please use the Code button for blocks of code you insert in the forum - your post above is almost unreadable. On to your problem... As I understand it you are rendering a category page (cars, bikes, etc), and you have some posts which are tagged with these same category pages in a Page Reference field (a post is tagged with cars, bikes, etc). Therefore your selector would be: $results = $pages->find("template=templateblogpost, category=$page, limit=5, sort=-postdate"); Note the double-quote marks around the selector string, so that the $page variable will be interpolated. Then foreach() $results to output your markup.
  13. @BitPoet's groupBy() hook is nice for this sort of thing. As with @teppo's suggestion, you'd have to do a bit more to get it working with infinite scroll (the limit might fall in the middle of a day, in which case you wouldn't want the day heading added again on the next pagination).
  14. Also, there is a counter option built into PW for all textarea fields:
  15. Thanks for the replies. It's no problem to me to use the built-in PHP functions - just wanted to check I wasn't overlooking something.
  16. I was looking at the API docs for $session and couldn't see any way to get a unique identifier for the current session. I want to use this to create a name for a temp directory so that paths for files stored there for each visitor do not clash with each other. I can use PHP's session_id() function but I'm surprised there's no ProcessWire $session method for this. Does anyone know if there is a PW way to get an identifier for the current session that I'm missing?
  17. Not meaning to hijack this thread, but just curious what advantage you see to using an array that you later implode versus the more typical approach of using .= to concatenate to a selector string. Are you doing things like using an associative array that so that you can conditionally modify parts of the selector by key before you implode, or something like that? Or you just like to be able to more clearly see the different parts of the selector in a Tracy dump?
  18. Just my opinion: I'm not sure there's much advantage to doing that - selector arrays seem more trouble than they are worth. When you start needing things like OR groups and nested selectors (which you inevitably do) the array syntax gets quite verbose and frankly less readable than the string syntax (especially if you are already familiar with the string syntax). I can't locate the topic now but I remember @adrian working with selector arrays for a while and I think he ended up reverting back to selector strings because there were too many issues/hassles with the array syntax. Maybe he will correct me on that.
  19. This is great, thanks! It would be cool if there was a filter option to show only assets that are not in the modules directory.
  20. Not sure if you have in mind a site profile for generally sharing with the community, or something that is made available only to some specific users/clients. If it's the former I would think option 1 would be necessary if you want the profile to be usable by a wide audience. I expect there are many here who are not running Git or Composer. And as you say you would update the profile from time to time (not really different in that regard from a module you have authored). If it's the latter then another option could be @bernhard's Kickstart tool: You would provide users with Kickstart settings that point to a remote profile zip that does not include any third-party modules within it, and then add the third-party modules in the "recipe". That way a user who is installing the profile always gets the latest module versions. I suppose you could use the Kickstart approach for a generally shared site profile too but it comes back to the audience thing again. If PW beginners should also be able to use the profile then it's probably best if the profile can be installed as per the standard procedure without them needing to learn any additional tools.
  21. You must have an old version of FieldtypeTable - it has included Page column types since 2015: https://processwire.com/blog/posts/major-updates-to-profields-table-field/#new-support-for-single-and-multi-page-reference-fields
  22. Here's some JS for that, for a Table field named "table_select_once". Add the JS any way that suits you - with AdminOnSteroids, a hook before Page Edit execute, etc. $(function() { // Disable options already selected in another table row function disableSelectedOptions() { var $selects = $('.Inputfield_table_select_once select'); $selects.find('option').prop('disabled', false); $selects.each(function() { var $selected = $(this).find('option[value!=""]:selected'); if($selected.length) { $selects.not(this).find('option[value="' + $selected.val() + '"]').prop('disabled', true); } }); } // Disable selected options on DOM ready disableSelectedOptions(); // Disable selected options when select changes $(document).on('change', '.Inputfield_table_select_once select', disableSelectedOptions); });
×
×
  • Create New...