Jump to content

Robin S

Members
  • Content Count

    3,872
  • Joined

  • Last visited

  • Days Won

    229

Everything posted by Robin S

  1. I'm not quite sure if you mean thumbnails within the Files inputfield in the PW admin, or if you mean you want to resize the image file for the front-end. If it's the latter you could use a function or module method along these lines: function getResizedImageUrl(Pagefile $pagefile, $width, $height) { $variation_basename = $pagefile->basename(false) . ".{$width}x{$height}." . $pagefile->ext(); $variation_filename = $pagefile->pagefiles->path . $variation_basename; if(!is_file($variation_filename)) { copy($pagefile->filename, $variation_filename); $sizer = new ImageSizer($variation_filename); $sizer->resize($width, $height); } return $pagefile->pagefiles->url . $variation_basename; } $file = $page->files->first(); $resized_url = getResizedImageUrl($file, 400, 300);
  2. No, because you are finding Field objects these are neither empty nor not empty. Instead you need to check the values of the field names for the current page to see which are empty. Something like this... $i = 1; foreach($page->fields as $field) { // Limit to 3 non-empty field values if($i > 3) break; // Check if value is empty $value = $page->getFormatted($field->name); if($value instanceof WireArray) { if(!$value->count) continue; } else { if(!$value) continue; } // Do whatever with $field here echo "{$field->name}<br>"; $i++; }
  3. @BillH, another way to change such labels is to install LanguageSupport (you don't need to install any of the related language modules if you're not using multi-language in your site). Then edit the Default language under Setup and "translate" any strings in the ProcessPageEdit.module that you want to change.
  4. Personally I think it's best not to let editors choose font family or font size at all, lest your website ends up looking like a dog's breakfast. But to answer your question, you can use the Custom Config Options in the field settings: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-font_names https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-fontSize_sizes
  5. Another possibility: $clean = $sanitizer->purify($dirty, ['HTML.ForbiddenAttributes' => ['style']]);
  6. @r.loeber, I'm not sure why the "Default value" option that is available for most Page Reference inputfield types isn't available for Page List Select, Page List Select Multiple and Page Autocomplete, but I made a module that extends default value support to these inputfields:
  7. Page Reference Default Value Most ProcessWire core inputfield types that can be used with a Page Reference field support a "Default value" setting. This module extends support for default values to the following core inputfield types: Page List Select Page List Select Multiple Page Autocomplete (single and multiple) Seeing as these inputfield types only support the selection of pages a Page List Select / Page List Select Multiple is used for defining the default value instead of the Text / Textarea field used by the core for other inputfield types. This makes defining a default value a bit more user-friendly. Note that as per the core "Default value" setting, the Page Reference field must be set to "required" in order for the default value to be used. Screenshot https://github.com/Toutouwai/PageReferenceDefaultValue https://modules.processwire.com/modules/page-reference-default-value/
  8. In this part, each $addedField is already a Field object so you could simplify it to: $addedFields = $this->wire->fields->find('tags='.MODULE_NAME.''); foreach($addedFields as $addedField) { $this->wire->fields->delete($addedField); }
  9. @Roope, I've noticed that the "Enable JavaScript to view protected content" notice appears for significantly longer in >= v1.2.0 than it did in v1.1.1. In the screencasts below I'm refreshing the page and I've used my browser dev tools to slow the network speed down to "Fast 3G" to make the effect more obvious. In both cases the EMO script should already be in the browser's cache. v1.1.1 v1.2.3 Is there some way to speed things up so performance is closer to the older version? A couple of other little things... 1. Could you look at appending the module version number to the JS file src as a cache-busting querystring? Without that there can be problems if you upgrade/downgrade the module and the visitor has the JS from a different version cached in their browser. 2. I wonder if the module could use a <noscript> tag in some way so that the "Enable JavaScript to view protected content" is only visible to visitors who have JS disabled. If the visitor has JS enabled but EMO has not yet decoded the email address then the notice doesn't need to be seen and this would avoid the FOUC.
  10. I'm not sure if sorting like that is possible using "owner", but scenarios such as this are what prompted the Connect Page Fields module.
  11. This means that the value you are saving to the title field has had its special characters converted to HTML entities. You don't want this because the PW admin automatically applies htmlspecialchars() to the title and so the entities are being double-encoded. So if $baslik[1] is being entity encoded somewhere in your code then simply don't do this step, or if you are getting the value from somewhere where the value is already entity encoded then you can use html_entity_decode() or instruct $sanitizer->text to convert entities: $p->title = $wire->sanitizer->text($baslik[1], ['convertEntities' => true]);
  12. It's possible with a hook. In the "List of fields to display in the admin Page List" setting for the template, enter a string that identifies where the value from the first repeater will go, e.g. first_repeater_datetime. Don't put the normal { } delimiters around this string. Then add a hook like this in /site/ready.php: $wire->addHookAfter('ProcessPageListRender::getPageLabel', function(HookEvent $event) { $page = $event->arguments(0); $out = $event->return; if($page->template == 'your_template') { $datetime = ''; if($page->datetimes->count) { $first_item = $page->datetimes->first(); $datetime = $first_item->date . ' ' . $first_item->time; } $event->return = str_replace('first_repeater_datetime', $datetime, $out); } });
  13. Maybe @tpr has some experience he could share. He is the author of the ProcessNetteTester module which is relevant to this topic.
  14. @regesh, that's a pretty vague statement. A proper bug report needs to include an exact description of the bugs and steps to reproduce them. Otherwise it's difficult to respond. As far as I can see the module works with FieldtypeToggle just fine. If you want to match a Toggle field in a selector you have to use the integer value - that isn't specific to this module, it's the way the PW core works. And by "field_tab" do you mean the core "Fieldset in Tab (Open)" aka FieldtypeFieldsetTabOpen? The module also works fine with this fieldtype so I don't understand the problem. If instead you are talking about the tab option of the non-core FieldsetGroup module that is part of ProFields then I've added support for that in v0.2.2.
  15. Yes, what I'm saying is that if you have HTML Entity Encoder enabled for the Title field then you wont get the cut off title, because < will be encoded to &lt; and so strip_tags() will leave it alone. The issue you've raised probably hasn't been noticed before because PW has the HTML Entity Encoder textformatter applied to the Title field by default and it's rare to disable it. If you're wanting to avoid double-encoding by Twig then until the issue is fixed you could just encode the title field before Page List renders the label: $wire->addHookBefore('ProcessPageListRender::getPageLabel', function(HookEvent $event) { $page = $event->arguments(0); $page->title = htmlspecialchars($page->title); });
  16. Another approach to try: // Store page changes in custom property on $wire $wire->addHookAfter('Page(template=contact|sample)::changed', function(HookEvent $event) { $page = $event->object; $what = $event->arguments(0); $old = $event->arguments(1); $new = $event->arguments(2); $page_changes = $event->wire('page_changes') ?: []; $page_changes[$page->id][$what] = [ 'old' => $old, 'new' => $new, ]; $event->wire('page_changes', $page_changes); }); // Send email if there are page changes after the request is finished $wire->addHookAfter('ProcessWire::finished', function(HookEvent $event) { $page_changes = $event->wire('page_changes'); if($page_changes) { // Send the email using the values in $page_changes ... } });
  17. @xportde, the ouput is trimmed of whitespace because the field render makes use of TemplateFile::render and by default the trim option is set to true. /** * Trim leading/trailing whitespace from rendered output? * * @var bool * */ protected $trim = true; There's no built-in way to change that setting in the render() call but you can change it with a hook if it's important: $wire->addHookBefore('TemplateFile::render', function(HookEvent $event) { $tpl = $event->object; if($tpl->field && $tpl->field->name === 'your_field_name') { $tpl->setTrim(false); } });
  18. @gornycreative, thanks for the report. I was able to reproduce that in PW 3.0.161 when the Connect Page Fields module config has been saved with one or more of the field selects left empty. Should be fixed in v0.3.1.
  19. @digitex, thanks for alerting me to this issue. I've made a change in v0.2.0 that should solve the issue. A note for all users of the module... Before v0.2.0 the Custom Inputfield Dependencies module did not render an inputfield in Page Edit if it determined that the inputfield should be hidden. But this creates problems if the inputfield and its neighbours have column widths of less than 100%. So from v0.2.0 onwards hidden fields will be rendered in Page Edit and hidden with CSS, so effectively the same type of hiding as occurs with the core inputfield dependencies feature.
  20. And it's also unique AFAIK in being the only module in the directory that doesn't have a support thread, which isn't great because it causes questions to be scattered all across the PW forums. And potential users should probably interpret the absence of a support thread as meaning "you are on your own if you use this module".
  21. Well, this depends on if the stored value for the inputfield has been set as a property of the class. There are multiple different places you might use an inputfield and it's up to you to get the value you want to set to it. How you get it doesn't have anything to with InputfieldCheckboxes per se - you just need to make sure you are setting an array as the value. If the inputfield is used in the getModuleConfigInputfields() method of a module then the value stored in the module config is automatically set as a property of the module class. Alternatively, if you have a config field for an Inputfield module (in the getConfigInputfields() method) that is used with a PW field then this config data is stored on the field, because only the field has a record in the database. In other words there is a "fields" table but no "inputfields" table. So you can get the stored value from the $field object as you are doing, but arguably it's better to make use of the features that PW has built in to automatically populate Inputfield properties from the corresponding Field. The Field class has this code in the getInputfield() method: // custom field settings foreach($this->data as $key => $value) { if($inputfield instanceof InputfieldWrapper) { $has = $inputfield->hasSetting($key) || $inputfield->hasAttribute($key); } else { $has = $inputfield->has($key); } if($has) { if(is_array($this->trackGets)) $this->trackGets($key); $inputfield->set($key, $value); } } What this boils down to is: "For every data property set on this Field object, check to see if a property of that name exists on the Inputfield object used by this field. If it does, set the value stored on this Field object as a property of the Inputfield object". So to make use of this you just need to set a property name in your Inputfield module's init() method, so that the property can be seen to exist when Field::getInputfield() is called. And typically you would set a default value for this property when appropriate. You can see how this is done in InputfieldRadios for example: public function init() { $this->set('optionColumns', 0); parent::init(); } By doing this: 1. A default value of 0 is set for optionColumns 2. Any value for optionColumns that is stored on a corresponding Field object automatically becomes available in the InputfieldRadios class as $this->optionColumns.
  22. /** @var InputfieldCheckboxes $f */ $f = $modules->get('InputfieldCheckboxes'); $f->name = 'foo'; $f->label = 'Foo'; $f->addOptions([ 'red' => 'Red', 'green' => 'Green', 'blue' => 'Blue', ]); // The value will be an array e.g. ['red', 'blue'] $f->value = $this->foo; $inputfields->add($f);
  23. $wire->addHookBefore('InputfieldFile::fileAdded', function($event) { /** @var InputfieldFile $inputfield */ $inputfield = $event->object; $page = $inputfield->hasPage; if($page && $page->template == 'your_template') { // ... } });
  24. @schwarzdesign, I agree with your suggestion in the GitHub issue, but in terms of working around it double-check that you have the HTML Entity Encoder textformatter applied to the title field (it is by default after installing PW, and should be applied to all plain text fields). Because with that applied I don't experience the issue on a clean PW installation:
×
×
  • Create New...