-
Posts
1,306 -
Joined
-
Last visited
-
Days Won
13
Everything posted by Juergen
-
I am running PHP 7.0.22 so "[]" are not the problem.
-
Hello, today I have activated the Captain Hook Panel in Tracy for the first time and I always get this message: What should I do to prevent this? Where can I define the variable "paths"? Best regards
-
Hello, I have a hook which should copy the value of one field to another on special type of templates: $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments(0); $page->setOutputFormatting(false); if(in_array($page->template->name, array('event_specialbusinesshours', 'single-special-business-hours'))) { $page->endeventdate = $page->starteventdate; } }); The field value will be copied -> this works. The 2 fields are requiered. After pressing the save button I got the following message that the value is missing, but it is still there To eliminate this error I could set the second field to not required, but I want an explanation why a copied value with "hook before saveready" leads to such an error-message. Does the validation take place before this hook. If yes, which hook method should be used instead? Best regards
-
So I ended up with the slightly modificated code of abdus which works like a charme: wire()->addHookAfter('ProcessPageAdd::buildForm', function (HookEvent $e) { /** @var InputfieldForm $form */ $form = $e->return; $form->add([ 'type' => 'markup', 'value' => '<script> $("#template").prepend("<option value=0 selected>Please select</option>"); </script>' ]); $template = $form->getChildByName('template'); $template->attr('required', 1); }); Before pressing the save button: After pressing the save button an nothing was choosen:
-
Hello @abdus your code works, but it doesn´t solve my problem. I have the template selection not in my page template because I don´t want to allow the user to change the template. The selection has to be taken before the new page is created. This is necessary because there are different UIs (forms) for the different type of templates. This is the place where the user have to select the template type: At the top the user has to select the prefered template type depending on which kind of page he wants to create (Business vacation, Event, Default date or Special openinghours). Depending on this selection the corresponding input form will be loaded. The problem: There is always one template type selected and no user action needs to be taken, but I want to force the user to select the type on his own - so he has to consider what kind of event he wants to create. So instead of a pre-selected template type I want an option like "make a choice" so the user has to select one. My idea was to add another template called "make a choice" which appear on the first place and has no function. Afterwards I make a custom validation via a hook. If this template selection was not changed to another template type the user gets an error messages to select a template type. But maybe there will be another more simple solution.
-
Thanks for the quick response. I have tried this before but it doesnt seem to work. This was because I had a writing mistake in my code. Now it works
-
Hi @bernhard I want to make the colheaders multilingual. Is ther a way to achive this in simple way or is it necessary to change the default textarea into a multilingual textarea? Best regards
-
Thanks @Robin S, your version is much cleaner.
-
With this little tutorial I want to show you how you can change the text of the add new button inside the children tab. This is the default button text which will be rendered on every template where children are allowed: And this is how it look likes after the manipulation: So it is a little bit customized. Maybe you can make it also with JS but I show you a way to change it via a hook inside the ready.php. Copy and adapt the following code into your ready.php. $pages->addHook('ProcessPageEdit::buildForm', function($event) { $page = $this->pages->get($this->input->get->id); $template = $this->pages->get($this->input->get->id)->template; //run the code only on the following templates -> adapt it to your needs if(($template == "event_events") || ($template == "event_dates") || ($template == "event_businessvacations") || ($template == "event_specialbusinesshours")) { $form = $event->return; $field = $event->object; $href = $this->config->urls->admin.'page/add/?parent_id='.$page; $field = $this->modules->get('InputfieldButton'); $field->attr('id+name', 'add_event'); $field->attr('class', $field->class); $field->attr('value', 'Add new event'); $field->attr('href',$href); $field->attr('icon','plus-circle'); $form->insertAfter($field, $form->get("AddPageBtn")); $form->remove($form->get("AddPageBtn")); } }); You can use the code as it is, but you have to adapt the if conditions to run it only on the templates you want. In my case I run it on 4 different templates. You can also change the icon if you want. Hope this will be helpful for some of you!
-
Hello @ all, I have a template select in my calendar template, where the user can choose if the new created page should use the template of a company vacation, special opening hours, an event or a default date. It is the template select which will be taken before a new child page will be created. Most of the time the user didnt take care of this select function and creates a page with the pre-selected template. After creating the page the user recognizes, that this is the wrong template and he has to delete the newly created page before creating a new child page with the correct template. My question: Is it possible, fe via a hook, to add a "select template" option at the top of this select, so that the user has to select the correct template first? Otherwise he will get an error. This would be a real enhancement to the workflow. Best regards
-
Very useful if you want to create automatic breadcrumbs via a function. I had this problem by creating child pages under a parent that should not be displayed via a real URL. The parent was only to categorize the content. But in the breadcrumbs it was displayed. In my case I solved it by categorize the children via different templates, but if you have only one template for the children, this solution will not work any longer.
-
For all of you who do not want to install a module: I have written a code snippet which could be copied into the ready.php. But first of all you have to include the Simple HTML dom parser to your project - I recommend to install it via composer. This is important because the manipulation of the markup depends on this library. I use the manipulations only on my "body" field, so therefore I wrote if($page->template->hasField('body')){ but you can change the name of the field according to your needs. So here we go: Copy this code into your ready.php /** * UIkit Textformatter for body field * * Changes various HTML elements to UIKit markup elements in the body field * * Tables * Unordered lists * Unordered list items * Ordered lists * Tooltips on links * Blockquotes */ if($page->template->hasField('body')){ $bodydom = HtmlDomParser::str_get_html($page->body); if (!empty($bodydom)) { //tables $tables = $bodydom->find('table'); foreach($tables as $table){ $table->style = null; $table->cellspacing = null; $table->cellpadding = null; $table->border = null; if($table->class){ $table->class = 'uk-table '.$table->class; } else { $table->class = 'uk-table'; } } //unordered lists $ulists = $bodydom->find('ul'); foreach($ulists as $list){ if($list->class){ $list->class = 'contentlist uk-list uk-list-space '.$list->class; } else { $list->class = 'contentlist uk-list uk-list-space'; } } //unordered list items foreach($bodydom->find('ul li') as $li){ $li->innertext = $li->innertext; } //ordered lists $olists = $bodydom->find('ol'); foreach($olists as $list){ if($list->class){ $list->class = 'custom-counter '.$list->class; } else { $list->class = 'custom-counter'; } } //textlinks $anchors = $bodydom->find('a'); foreach($anchors as $a){ if(!empty(strip_tags($a->innertext))){ $a->class = "textlink"; $a->{'data-uk-tooltip'} = ''; } } //blockquotes $blockquotes = $bodydom->find('blockquote'); foreach($blockquotes as $b){ $b->innertext = '<i class="fa fa-quote-left fa-2x uk-align-left"></i>'.$b->innertext; } //Manipulating figcaption with uikit css class foreach (($bodydom->find('figcaption')) as $caption) { $caption->class = 'uk-thumbnail-caption'; //add class to figure caption tag } foreach (($bodydom->find('img')) as $img) { //manipulate image links with tooltip and lightbox attributes if ($img->parent->tag == 'a') { $pageId = (int) wire($this->page)->get('id'); //get current page id for lightbox group $img->parent->{'data-uk-tooltip'} = ''; //add tooltip attribute $img->parent->{'data-uk-lightbox'} = '{group:\'' . $pageId . '\'}'; //add lightbox attribute if ($img->alt) { $img->parent->title = $img->alt; //add alt attribute as anchor title } else { $img->parent->title = __("Lightbox view of the image"); //add default anchor title } } //create case types if (($img->parent->tag != 'a') && ($img->parent->tag != 'figure')) { $case = 'img'; } if (($img->parent->tag == 'a') && ($img->parent->parent->tag != 'figure')) { $case = "a img"; } if ($img->parent->tag == 'figure') { $case = "figure img"; } if (($img->parent->tag == 'a') && ($img->parent->parent->tag == 'figure')) { $case = "figure a img"; } switch ($case) { case 'img': //create space before image class if ($img->class) { $img->class = ' ' . $img->class; } $img->class = 'uk-thumbnail' . $img->class; if (strpos($img->class, 'align_left') !== false) { $img->class = str_replace('align_left', 'uk-align-left', $img->class); } elseif (strpos($img->class, 'align_right') !== false) { $img->class = str_replace('align_right', 'uk-align-right', $img->class); } elseif (strpos($img->class, 'align_center') !== false) { $img->class = str_replace('align_center', 'uk-align-center uk-text-center', $img->class); } else { $img->class = $img->class . ' no-align'; $img->outertext = '<span class="uk-display-block uk-margin-bottom">' . $img->outertext . '</span>'; } break; case 'a img': $img->parent->class = 'uk-thumbnail ' . $img->class; if (strpos($img->class, 'align_left') !== false) { $img->parent->class = str_replace('align_left', 'uk-align-left', $img->parent->class); $img->outertext = '<span class="uk-overlay uk-overlay-hover">' . $img->outertext . '<span class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></span></span>'; } elseif (strpos($img->class, 'align_right') !== false) { $img->parent->class = str_replace('align_right', 'uk-align-right', $img->parent->class); $img->outertext = '<span class="uk-overlay uk-overlay-hover">' . $img->outertext . '<span class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></span></span>'; } elseif (strpos($img->class, 'align_center') !== false) { $img->parent->class = str_replace('align_center', 'uk-align-center uk-display-inline-block', $img->parent->class); $img->outertext = '<span class="uk-overlay uk-overlay-hover">' . $img->outertext . '<span class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></span></span>'; $img->parent->outertext = '<span class="uk-display-block uk-text-center test">' . $img->parent->outertext . '</span>'; } else { $img->parent->class = $img->class . ' no-align uk-thumbnail'; $img->outertext = '<span class="uk-overlay uk-overlay-hover">' . $img->outertext . '<span class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></span></span>'; $img->parent->outertext = '<span class="uk-display-block uk-margin-bottom">' . $img->parent->outertext . '</span>'; } $img->class = null; break; case 'figure img': if (strpos($img->parent->class, 'align_left') !== false) { $img->parent->class = str_replace('align_left', 'uk-align-left', $img->parent->class); } elseif (strpos($img->parent->class, 'align_right') !== false) { $img->parent->class = str_replace('align_right', 'uk-align-right', $img->parent->class); } elseif (strpos($img->parent->class, 'align_center') !== false) { $img->parent->class = str_replace('align_center', 'uk-align-center uk-text-center', $img->parent->class); } else { $img->parent->class = 'uk-display-inline-block no-align'; } $img->class = 'uk-thumbnail'; break; case 'figure a img': if (strpos($img->parent->parent->class, 'align_left') !== false) { $img->parent->parent->class = str_replace('align_left', 'uk-align-left', $img->parent->parent->class); $img->outertext = '<div class="uk-overlay uk-overlay-hover">' . $img->outertext . '<div class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></div></div>'; } elseif (strpos($img->parent->parent->class, 'align_right') !== false) { $img->parent->parent->class = str_replace('align_right', 'uk-align-right', $img->parent->parent->class); $img->outertext = '<div class="uk-overlay uk-overlay-hover">' . $img->outertext . '<div class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></div></div>'; } elseif (strpos($img->parent->parent->class, 'align_center') !== false) { $img->parent->parent->class = str_replace('align_center', 'uk-align-center uk-text-center', $img->parent->parent->class); $img->outertext = '<div class="uk-overlay uk-overlay-hover">' . $img->outertext . '<div class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></div></div>'; } else { $img->parent->parent->class = $img->parent->parent->class . ' no-align uk-display-inline-block'; $img->outertext = '<div class="uk-overlay uk-overlay-hover">' . $img->outertext . '<div class="uk-overlay-panel uk-overlay-background uk-overlay-icon"></div></div>'; } $img->parent->class = 'uk-thumbnail'; $img->class = null; break; } } //add manipulations to body field $page->body = $bodydom; } } Thats all! All these elements will be enriched with UIKit 2 Markup. Remember: If Simple HTML Dom Parser is not correctly installed, you will get an error. Some of the styles I use are the ones that I prefer. Maybe you prefer an other style that UIKit offers. So you can change the CSS classes to your prefered style. This code only should give you an inspiration on how to manipulate markup. Best regards.
-
Ideas and best practices to secure a member registration system
Juergen replied to modifiedcontent's topic in Security
I have also written the login/logout system on my own (I needed UIKit Markup and some other customizations). To prevent spam I use this Honeypot class and I have no problem since then. It make several tests before letting the user go further. I have installed it via composer so updating is also no problem. So its a look worth while. Best regards- 10 replies
-
- 2
-
- no subscription detected
- not recognized
-
(and 4 more)
Tagged with:
-
Thanks for the great module. It would be awesome if you make the link text " Generate password " translateable
-
Integrating working "required if" conditions in repeater
Juergen replied to Juergen's topic in Wishlist & Roadmap
I have created a set of inputfields for recurring events. There you can choose between daily, weekly, monthly yearly and you can choose between an enddate or a number of repeats (and of course some other options). The if condition depends on a select option fieldtype. If you choose "repeat until a certain enddate" then the enddate field needs to be filled out (required), if you choose to repeat the events until a certain number of repeats (fe 10 repeats), then the enddate field is not required. All the fields are in the new fieldset(Page) fieldtype. -
Integrating working "required if" conditions in repeater
Juergen replied to Juergen's topic in Wishlist & Roadmap
Because I would have to write a lot of hooks and that is what I want to prevent . -
How to copy fieldset(Page) values via API to a child page
Juergen replied to Juergen's topic in API & Templates
Ok, thanks for your tipps. It is not really necessary to put the fields inside a fieldset(Page) field - it would only save me a lot of time. I will put it inside a default fieldset and copy it as usual. -
Hello @ all, I am trying to copy the values of the new fieldset (Page) type fields via API to a child page. Its a kind of repeater so I have tried to copy it like this: $k->eventdatesfieldset->import((wire('pages')->get($page->id))->eventdatesfieldset); "eventdatesfieldset" is the name of the fieldset. I have tried it with the import function like in repeaters but I always get the message "Method FieldsetPage::import does not exist or is not callable in this context". Does anyone has tried to copy fields from this new fieldtype and has a working solution? I want to copy the values to the child page. Best regards
-
It would be great if "required if" conditions in repeaters inputfield dependencies will work in the future. At the moment only "show if" conditions work. Today I have implemented the new fieldset (Page) type, which works like a repeater. But unfortunately I had to remove it because of the non working "required if" conditions. In my case I need the "required if" condition and therefore I had to switch back to a default fieldset (which supports the "required if" condition dependency). But it was more work and I needed more fields. So this feature would save a lot of time. Maybe it will be possible in the near future. Would be great!
-
Hello @Missariella, however, I am using the latest dev version (3.0.76) and its working. First of all I recommend you to create a global translation piece of code. Put it somewhere in a file that is loaded everytime (fe. a function.php), so the translation code will be availiable everywhere. You can put it also in the template file where you want to output the select options, but loading it in general makes more sense in this case, because you can use it in other templates too. Here is the code: //get labels, title, values and descriptions in different languages if ($user->language->name != 'default') { $title = "title{$user->language}"; $value = "value{$user->language}"; $label = "label{$user->language}"; $description = "description{$user->language}"; $notes = "notes{$user->language}"; } else { $title = 'title'; $value = 'value'; $label = 'label'; $description = 'description'; $notes = 'notes'; } This little code snippet makes titles, values, labels, descriptions and notes available in all languages by only calling "$title" instead of "title" (or "$label" instead of "label" and so on...). So it makes your life much easier Afterwards creating a multilanguage select can be done like this: $options = $fieldtypes->get('FieldtypeOptions')->getOptions($fields->get('YOURFIELDNAME')); foreach ($options as $value) { echo $value->$title; echo $value->$label; echo $value->$description; } This outputs title, label and description in the user language. This is the code that I am using on my projects without any problems.