Jump to content
teppo

SearchEngine

Recommended Posts

@teppo Perhaps my comment from February got lost in the mix.

This search function is such a great addition to the ProcessWire ecosystem.

I am wondering if you would consider adding FieldsetPage fields to the list of searchable fields?

I use FieldsetPage fields often to create components. From there it is a mater of adding that one field to a template or a repeater to add the component.

Thank you for your time.

Share this post


Link to post
Share on other sites
1 hour ago, GhostRider said:

I am wondering if you would consider adding FieldsetPage fields to the list of searchable fields?

I use FieldsetPage fields often to create components. From there it is a mater of adding that one field to a template or a repeater to add the component.

Sorry for taking so long to reply — this is now the top item on my todo list. I'll try to get it included sometime soon!

  • Like 2

Share this post


Link to post
Share on other sites

@GhostRider, FieldsetPage support is now included with module version 0.20.0. I didn't have much to test with, but it did seem to work as expected on my limited use case — let me know if you run into any issues and I'll be happy to take a closer look 🙂

  • Like 2

Share this post


Link to post
Share on other sites

Hi @teppo. Thanks for addressing this. I'll give it a test drive later today or tomorrow on a current project.

  • Like 1

Share this post


Link to post
Share on other sites

@teppo Thanks for your help! Sorry for the delay (and sorry I have to get back to this). Yes, you're right, I use Hanna Code on my site. My code works fine though except when called by your indexer. I noticed another thing: When trying to save the page which calls my HC, PW gives the same error as above.

This is the content of my HC causing the trouble:

if($page->images_gallery->count()) { // images_gallery is a repeater field
	$gallery = "<div class='gallery'>";
	foreach($page->images_gallery as $img) {
	    if($img->image_caption) {
		    $titleAttr = "title='" . strip_tags($img->image_caption) . "'";
		    $imgCaption = "<div class='lightbox-caption'>$img->image_caption</div>";
	    } else {
	        $titleAttr = "";
	        $imgCaption = "";
	    }
		$gallery .= "
			<a href='{$img->image->url}' $titleAttr>
				<img src='" . $img->image->size(250, 250)->url . "' alt='" . $img->image->description . "'>
				$imgCaption
			</a>
		";
	}
	$gallery .= "</div>";
	echo $gallery;
}

This is tailored to output formatting being on, as is usually the case when HC is called. How does your indexer handle OF when it pulls content from fields? I'm still confused by the fact that triggering your indexer via API does NOT lead to any error. The error seems to appear only when the backend is "involved". Any ideas? Thanks a lot!

Share this post


Link to post
Share on other sites

Hi @teppo, thanks very much for creating this module.

We are looking to include a site search on a client's website. The website uses sub pages as on-page blocks that are rendered out as part of the parent page (allows for some nice flexible layouts). Do you know if this module would be suitable for also searching through these blocks and displaying the relative parent link in the search results?

Share this post


Link to post
Share on other sites

Hy, Thanks for the module.

Just wanted to try it today. An upon uploading the module on my processwire installation. I got this parse error message (syntax error, unexpected '?' line 478).
I am running it on the latest stable processwire version and php 7.x.

Thanks in advance

 

Share this post


Link to post
Share on other sites
On 4/16/2020 at 12:04 PM, CalleRosa40 said:

@teppo Thanks for your help! Sorry for the delay (and sorry I have to get back to this). Yes, you're right, I use Hanna Code on my site. My code works fine though except when called by your indexer. I noticed another thing: When trying to save the page which calls my HC, PW gives the same error as above.

...

This is tailored to output formatting being on, as is usually the case when HC is called. How does your indexer handle OF when it pulls content from fields? I'm still confused by the fact that triggering your indexer via API does NOT lead to any error. The error seems to appear only when the backend is "involved". Any ideas? Thanks a lot!

Sorry for the delay from my part as well... 😅

Indexer grabs the value using $page->getFormatted($field_name). This means that output formatting is temporarily enabled for the page, value is read, and then output formatting is disabled (assuming it was disabled in the first place).

I'm not able to make this work via the API either — getting the same error there, so I'm also somewhat confused about this. Could mean that there's some difference in the way we're testing this. Anyway, both $page->save() and direct call to SearchEngine::indexPage($page) lead to the exact same error in my tests using your Hanne Code snippet 🙂

In this case the problem seems to be that your Hanna Code snippet is accessing Repeater Pages that were loaded with output formatting disabled (FieldtypeRepeater::___wakeupValue()). I've been trying to work around this for a while now, but to be honest I have no idea how to do that without causing potential issues and/or slowdowns elsewhere. I do have a couple of ideas I'd like to try, but it may take a while to figure this out, and even then the conclusion could be that this is simply too much of a hassle to automatically handle in SearchEngine.

The TL;DR here is that at least for the time being a slight modification is required for the Hanna Code snippet:

	foreach($page->images_gallery as $img) {
		$img->of(true);

(Or, alternatively, you could get $img->image with $img->getFormatted('image').)

I'll keep trying, but I can't give you any promises regarding a possible future Hanna Code compatibility enhancement yet 🙂

  • Like 1

Share this post


Link to post
Share on other sites
On 5/4/2020 at 11:52 AM, 999design said:

We are looking to include a site search on a client's website. The website uses sub pages as on-page blocks that are rendered out as part of the parent page (allows for some nice flexible layouts). Do you know if this module would be suitable for also searching through these blocks and displaying the relative parent link in the search results?

Hey @999design!

SearchEngine can handle pages that are stored in PageTable or Repeater fields automatically, but if you're literally using subpages and there's no backend / field level connection between the parent and the children, then this would (at least for now) require a custom hook. In other words you can use SearchEngine, but you'll have to add a bit of extra code to populate the index.

Something like this should do it:

$wire->addHookAfter('SearchEngine::savedPageIndex', function(HookEvent $event) {
	$page = $event->arguments[0];
	if ($page->template == 'ContainerPage' && $page->children->count()) {
		$searchEngine = $event->modules->get('SearchEngine');
		foreach ($page->children as $child) {
			$child_index = $searchEngine->indexPage($child, false, [
				'return' => 'index',
			]);
			$page->search_index .= "\n" . $child_index[0];
		}
		$page->save('search_index', [
			'quiet' => true,
			'noHooks' => true,
		]);
	}
});

Note that you need to use SearchEngine 0.21.0 for this to work; I just released a new version that made Indexer::indexPage() a bit more flexible. Also note that if you're building a multi-lingual site, indexPage() will return an array where the index is language ID, and you'll need to use setLanguageValue() to store it for each language one by one 🙂

  • Like 4

Share this post


Link to post
Share on other sites
9 hours ago, antpre said:

Hy, Thanks for the module.

Just wanted to try it today. An upon uploading the module on my processwire installation. I got this parse error message (syntax error, unexpected '?' line 478).
I am running it on the latest stable processwire version and php 7.x.

Hey @antpre!

Could you check what's on that line and paste it here, and also double check your PHP version? If I'm looking at the correct line of code, 478 should be this one:

    public function createIndexField(string $index_field_name, string $redirect_url = null): ?Field {

... and if that's the case, the only matching issue I can think of would be the use of nullable return type ("?Field"). Support for nullable return types was added in PHP 7.1, so this would suggest that either you're running an earlier version of PHP, or there's something else wrong with the setup (or perhaps I've got the wrong line) 🙂

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, teppo said:

Hey @999design!

SearchEngine can handle pages that are stored in PageTable or Repeater fields automatically, but if you're literally using subpages and there's no backend / field level connection between the parent and the children, then this would (at least for now) require a custom hook. In other words you can use SearchEngine, but you'll have to add a bit of extra code to populate the index.

Something like this should do it:


$wire->addHookAfter('SearchEngine::savedPageIndex', function(HookEvent $event) {
	$page = $event->arguments[0];
	if ($page->template == 'ContainerPage' && $page->children->count()) {
		$searchEngine = $event->modules->get('SearchEngine');
		foreach ($page->children as $child) {
			$child_index = $searchEngine->indexPage($child, false, [
				'return' => 'index',
			]);
			$page->search_index .= "\n" . $child_index[0];
		}
		$page->save('search_index', [
			'quiet' => true,
			'noHooks' => true,
		]);
	}
});

Note that you need to use SearchEngine 0.21.0 for this to work; I just released a new version that made Indexer::indexPage() a bit more flexible. Also note that if you're building a multi-lingual site, indexPage() will return an array where the index is language ID, and you'll need to use setLanguageValue() to store it for each language one by one 🙂

That's amazing, thank you very much for the detailed reply @teppo . We now have a few good options to suggest to our client.

Much appreciated 🙂

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your answer... and indeed i am runing php 7.0.33.

Regards

Share this post


Link to post
Share on other sites

It’s been a while since I developed a new project with PW, but I have an upcoming client/project that could certainly use SearchEngine. I have a question about search results:

Is SearchEngine able to return results into groups? For instance, the client is a home builder/seller. If a user performs a search, it would be nice to return the results as sets. In their case, single-floor homes; two-story homes; etc. That’s just an example. The bottom line is that their homes are divided into categories, so it would be nice if users could see results grouped as such.

Is this possible?

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, fuzenco said:

Is SearchEngine able to return results into groups? For instance, the client is a home builder/seller. If a user performs a search, it would be nice to return the results as sets. In their case, single-floor homes; two-story homes; etc. That’s just an example. The bottom line is that their homes are divided into categories, so it would be nice if users could see results grouped as such.

Is this possible?

At the moment SearchEngine doesn't have built-in support for this.

That being said: you could create a custom search page and use SearchEngine to index and (optionally) find items, which you then output manually. Or you could hook into Renderer::renderResults() and customize the output there. So yeah, there are ways to handle this, but it will require a bit of extra work 🙂

Out of interest: is each group going to contain items of a single template, i.e. in your example would "single-floor home" and "two-story home" be templates, or would this be some sort of option on a shared template (integer, options field, or something along those lines)? Grouping results by template might actually be a good idea as a built-in feature, just wondering if that'd work in your case.

  • Like 1

Share this post


Link to post
Share on other sites
On 7/16/2019 at 9:41 AM, teppo said:

Anyway, currently the ("full", i.e. a form and a results list) rendered state looks like this:

 

#1 "Full" result
How can I get this "full" result? The "standard" rendering outputs just the title and the URL.

#2 Languages
I assume that it needs "manual" rendering to output a language specific output … instead of english ("Search results", "x results for:", and so on) …

#3 Select (product) field
Taking consideration of #1 and #2 … I have a repeater matrix in the basic-page(es). I use manual indexing in the SearchEngine Module. RepeaterMatrix > Text fields are working well with this setup. I set the "search_index" field to "visible in editor" and this is what it stores (for example in french):

Vente au détail Solutions pour votre application de vente au détail Si vous êtes propriétaire d'un appartement, responsable d'un datacentre ou directeur d'hôtel, nous avons des exemples et des solutions pour chaque besoin d'application. Array Exemples &amp; Solutions : Array Array Array Array 
{}

(…there's a lot of "Array" here… hmm…)

One of the repeater matrix items is just an option field (to select a product category [green products, yellow products, brown products…]). This is just an information what to render in frontend, but the product texts are stored in different pages. So there is no text/product-infos to store in the "search_index" field.

How can I manage to insert the selected products into the "search_index" field?

My first thought was to add a new field to the template… let's call it "search_dump". On every "page save" I populate this text area according to the RepeaterMatrix -> product_selection field (I guess this can be done by a hook). Then I have to recreate the search index manually in the backend GIU or by API:

$modules->get('SearchEngine')->indexPage($page);

Share this post


Link to post
Share on other sites
On 5/23/2020 at 11:05 AM, teppo said:

Out of interest: is each group going to contain items of a single template, i.e. in your example would "single-floor home" and "two-story home" be templates, or would this be some sort of option on a shared template (integer, options field, or something along those lines)? Grouping results by template might actually be a good idea as a built-in feature, just wondering if that'd work in your case.

Generally, this would be a shared template as the homes all contain the same content blocks (title, description, number of bedrooms, number of bathrooms, picture gallery, etc.). The only difference really is the classification of homes. Years ago, I used to work with the CMS Expression Engine which would allow for this type of grouping. I can’t remember how it did it, but it was was useful.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, fuzenco said:

Generally, this would be a shared template as the homes all contain the same content blocks (title, description, number of bedrooms, number of bathrooms, picture gallery, etc.). The only difference really is the classification of homes. Years ago, I used to work with the CMS Expression Engine which would allow for this type of grouping. I can’t remember how it did it, but it was was useful.

Thanks for the clarification 🙂

Grouping can be done by pretty much any imaginable way with ProcessWire data types as well, but I was wondering if this would be solvable with something that's "generic enough" to be added to the module as a feature. Technically I could add settings for grouping with custom fields etc. as well, but that sounds like it would be a lot more complex — as a module setting, meaning that it would have to work with a lot of different configurations — than just by template.

  • Like 1

Share this post


Link to post
Share on other sites
On 5/25/2020 at 6:36 PM, 2hoch11 said:

#1 "Full" result
How can I get this "full" result? The "standard" rendering outputs just the title and the URL.

The view in the screenshot is what you should get by calling  <?= $modules->get('SearchEngine')->render() ?>.

If you mean that you get the search form and a list of results but the results don't have a summary field, then it's possible that you need to define the summary field — this is assuming that your pages don't actually have a filled-in summary field on them:

$config->SearchEngine = [
    'render_args' => [
        // Summary of each result (in the search results list) is the value of this field.
        'result_summary_field' => 'summary',
    ],
];
On 5/25/2020 at 6:36 PM, 2hoch11 said:

#2 Languages
I assume that it needs "manual" rendering to output a language specific output … instead of english ("Search results", "x results for:", and so on) …

These are all translatable strings — so no, manual rendering is not needed, you just need to translate the module files to your language 🙂

On 5/25/2020 at 6:36 PM, 2hoch11 said:

#3 Select (product) field
Taking consideration of #1 and #2 … I have a repeater matrix in the basic-page(es). I use manual indexing in the SearchEngine Module. RepeaterMatrix > Text fields are working well with this setup. I set the "search_index" field to "visible in editor" and this is what it stores (for example in french):


Vente au détail Solutions pour votre application de vente au détail Si vous êtes propriétaire d'un appartement, responsable d'un datacentre ou directeur d'hôtel, nous avons des exemples et des solutions pour chaque besoin d'application. Array Exemples &amp; Solutions : Array Array Array Array 
{}

(…there's a lot of "Array" here… hmm…)

The array part is interesting. perhaps options field (if I understood the next part correctly and this is what you're using here) isn't getting indexed quite right; I'll take a closer look at that soon.

On 5/25/2020 at 6:36 PM, 2hoch11 said:

One of the repeater matrix items is just an option field (to select a product category [green products, yellow products, brown products…]). This is just an information what to render in frontend, but the product texts are stored in different pages. So there is no text/product-infos to store in the "search_index" field.

How can I manage to insert the selected products into the "search_index" field?

My first thought was to add a new field to the template… let's call it "search_dump". On every "page save" I populate this text area according to the RepeaterMatrix -> product_selection field (I guess this can be done by a hook). Then I have to recreate the search index manually in the backend GIU or by API:


$modules->get('SearchEngine')->indexPage($page);

The code I posted a few replies ago on this thread was actually almost directly applicable to your case as well. Here's a rough idea — you still need to fill in the blanks, most importantly the way you're fetching those products:

$wire->addHookAfter('SearchEngine::savedPageIndex', function(HookEvent $event) {
	$page = $event->arguments[0];
	if ($page->template == 'TemplateWithProducts') {
		$searchEngine = $event->modules->get('SearchEngine');

        // I don't know exactly how you're fetching those products; include your logic here :)
        $products = $pages->find('template=product, some_rule=' . $page->some_field);

        foreach ($products as $product) {
            $product_index = $searchEngine->indexPage($product, false, [
				'return' => 'index',
			]);
			$page->search_index .= "\n" . $product_index[0];
        }
		$page->save('search_index', [
			'quiet' => true,
			'noHooks' => true,
		]);
	}
});

Note that if this is a multi-lingual site, that will require some additional tweaks (indexPage() will return an index value per language, and you need to use setLanguageValue() to store it).

Let me know if any of this doesn't seem quite right, and I'll be happy to take a closer look 🙂

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi,

I installed Search Engine and it looks like it's working. Thank you! I just noticed I now have this error every time I save a blog entry.

"Method Pageimages::width does not exist or is not callable in this context"

Based on a previous reply, it appears it's a hanna code issue, but this code does output an image on the front end... Is there something wrong with it?

 

$page=$pages->get($id); //gets the page
    
$image = $page->image->width(1240, ["suffix" => "srcset"]); //create image that is 1200px wide

Thank you for any clues on how to fix it.

Regards,

 

Share this post


Link to post
Share on other sites

Hey @montero4,

First of all, just wanted to say that I really need to figure out some way to handle these conflicts with Hanna Code — it's becoming a common issue. I'll see what I can do about that soon 🙂

Technically there's nothing wrong in your code. It will work just fine on the front-end, where it's really intended to run. The problem is that in order to get useful index out of field content, SearchEngine actually gets it via $page->getFormatted(), which means that TextFormatters (such as Hanna Code) will also run in the admin side.

In this case you're using $pages->get() to get another Page, and since the default in the admin is that output formatting is off, this means that this new Page will have output formatting disabled — and that's why $page->image actually returns an instance of Pageimages (instead of a single Pageimage).

... anyway, just wanted to explain what's going on in here 🙂

Right now the easy fix would be checking for the type in the Hanna Code snippet. (Again, I'd like to automatically handle this in SearchEngine, but I can't say for sure when I'll get to that.)

$page=$pages->get($id); //gets the page
    
$image = $page->image instanceof Pageimages ? $page->image->eq(0) : $page->image;
$image = $image->width(1240, ["suffix" => "srcset"]); //create image that is 1200px wide

Alternatively you could make sure that output formatting state is on — it's mostly a matter of taste, really:

$page=$pages->get($id); //gets the page

$of = $page->of() // store initial output formatting state for later use
$page->of(true); // make sure that output formatting is on
    
$image = $page->image->width(1240, ["suffix" => "srcset"]); //create image that is 1200px wide

$page->of($of); // restore initial output formatting state

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Using the module on a multi-language site. When saving a page, I get the following error: "Call to a member function setLanguageValue() on string", File: .../modules/SearchEngine/lib/Indexer.php:99

 98:                        if ($index_field_exists) {
 99:                            $page->get($index_field)->setLanguageValue($language, $index[$language->id]);
101:                        }

I suppose we need a $page->of(false) here before calling setLanguageValue() ?

Share this post


Link to post
Share on other sites
On 5/26/2020 at 10:41 AM, teppo said:

Thanks for the clarification 🙂

Grouping can be done by pretty much any imaginable way with ProcessWire data types as well, but I was wondering if this would be solvable with something that's "generic enough" to be added to the module as a feature. Technically I could add settings for grouping with custom fields etc. as well, but that sounds like it would be a lot more complex — as a module setting, meaning that it would have to work with a lot of different configurations — than just by template.

Yes, I can imagine it would be complex. I think ExpressionEngine did it by means of an inline group-by. For instance:

<li class="whatever" groupby="datacolumn">

And then there was a sort-by also:

<li class="whatever" groupby="datacolumn" sortby="whatever">

 

  • Like 1

Share this post


Link to post
Share on other sites

 

Hi @teppo,

thanks for the great module, we already use it with several customers.

I have a question concerning the savePageIndex-Hook: It works perfectly on saving a single page, but not, when I use the "Index pages now"-function in module settings page. How could I achieve this?

Best regards,

Thomas.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By teppo
      Needed a really simple solution to embed audio files within page content and couldn't find a module for that, so here we go. Textformatter Audio Embed works a bit like Textformatter Video Embed, converting this:
      <p>https://www.domain.tld/path/to/file.mp3</p> Into this:
      <audio controls class="TextformatterAudioEmbed"> <source src="https://www.domain.tld/path/to/file.mp3" type="audio/mpeg"> </audio> The audio element has pretty good browser support, so quite often this should be enough to get things rolling 🙂
      GitHub repository: https://github.com/teppokoivula/TextformatterAudioEmbed Modules directory: https://modules.processwire.com/modules/textformatter-audio-embed/
    • By Richard Jedlička
      Tense    
      Tense (Test ENvironment Setup & Execution) is a command-line tool to easily run tests agains multiple versions of ProcessWire CMF.
      Are you building a module, or a template and you need to make sure it works in all supported ProcessWire versions? Then Tense is exactly what you need. Write the tests in any testing framework, tell Tense which ProcessWire versions you are interested in and it will do the rest for you.

      See example or see usage in a real project.
      How to use?
      1. Install it: 
      composer global require uiii/tense 2. Create tense.yml config:
      tense init 3. Run it:
      tense run  
      For detailed instructions see Github page: https://github.com/uiii/tense
       
      This is made possible thanks to the great wireshell tool by @justb3a, @marcus and others.
       
      What do you think about it? Do you find it useful? Do you have some idea? Did you find some bug? Tell me you opinion. Write it here or in the issue tracker.
    • By Chris Bennett
      Hi all, I am going round and round in circles and would greatly appreciate if anyone can point me in the right direction.
      I am sure I am doing something dumb, or missing something I should know, but don't. Story of my life 😉

      Playing round with a module and my basic problem is I want to upload an image and also use InputfieldMarkup and other Inputfields.
      Going back and forth between trying an api generated page defining Fieldgroup, Template, Fields, Page and the InputfieldWrapper method.

      InputfieldWrapper method works great for all the markup stuff, but I just can't wrap my head around what I need to do to save the image to the database.
      Can generate a Field for it (thanks to the api investigations) but not sure what I need to do to link the Inputfield to that. Tried a lot of stuff from various threads, of varying dates without luck.
      Undoubtedly not helped by me not knowing enough.

      Defining Fieldgroup etc through the api seems nice and clean and works great for the images but I can't wrap my head around how/if I can add/append/hook the InputfieldWrapper/InputfieldMarkup stuff I'd like to include on that template as well. Not even sure if it should be where it is on ___install with the Fieldtype stuff or later on . Not getting Tracy errors, just nothing seems to happen.
      If anyone has any ideas or can point me in the right direction, that would be great because at the moment I am stumbling round in the dark.
       
      public function ___install() { parent::___install(); $page = $this->pages->get('name='.self::PAGE_NAME); if (!$page->id) { // Create fieldgroup, template, fields and page // Create new fieldgroup $fmFieldgroup = new Fieldgroup(); $fmFieldgroup->name = MODULE_NAME.'-fieldgroup'; $fmFieldgroup->add($this->fields->get('title')); // needed title field $fmFieldgroup->save(); // Create new template using the fieldgroup $fmTemplate = new Template(); $fmTemplate->name = MODULE_NAME; $fmTemplate->fieldgroup = $fmFieldgroup; $fmTemplate->noSettings = 1; $fmTemplate->noChildren = 1; $fmTemplate->allowNewPages = 0; $fmTemplate->tabContent = MODULE_NAME; $fmTemplate->noChangeTemplate = 1; $fmTemplate->setIcon(ICON); $fmTemplate->save(); // Favicon source $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeImage"); $fmField->name = 'fmFavicon'; $fmField->label = 'Favicon'; $fmField->focusMode = 'off'; $fmField->gridMode = 'grid'; $fmField->extensions = 'svg png'; $fmField->columnWidth = 50; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon(ICON); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($fmField); // Favicon Silhouette source $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeImage"); $fmField->name = 'fmFaviconSilhouette'; $fmField->label = 'SVG Silhouette'; $fmField->notes = 'When creating a silhouette/mask svg version for Safari Pinned Tabs and Windows Tiles, we recommend setting your viewbox for 0 0 16 16, as this is what Apple requires. In many cases, the easiest way to do this in something like illustrator is a sacrificial rectangle with no fill, and no stroke at 16 x 16. This forces the desired viewbox and can then be discarded easily using something as simple as notepad. Easy is good, especially when you get the result you want without a lot of hassle.'; $fmField->focusMode = 'off'; $fmField->extensions = 'svg'; $fmField->columnWidth = 50; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon(ICON); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($fmField); // Create: Open Settings Tab $tabOpener = new Field(); $tabOpener->type = new FieldtypeFieldsetTabOpen(); $tabOpener->name = 'fmTab1'; $tabOpener->label = "Favicon Settings"; $tabOpener->collapsed = Inputfield::collapsedNever; $tabOpener->addTag(MODULE_NAME); $tabOpener->save(); // Create: Close Settings Tab $tabCloser = new Field(); $tabCloser->type = new FieldtypeFieldsetClose; $tabCloser->name = 'fmTab1' . FieldtypeFieldsetTabOpen::fieldsetCloseIdentifier; $tabCloser->label = "Close open tab"; $tabCloser->addTag(MODULE_NAME); $tabCloser->save(); // Create: Opens wrapper for Favicon Folder Name $filesOpener = new Field(); $filesOpener->type = new FieldtypeFieldsetOpen(); $filesOpener->name = 'fmOpenFolderName'; $filesOpener->label = 'Wrap Folder Name'; $filesOpener->class = 'inline'; $filesOpener->collapsed = Inputfield::collapsedNever; $filesOpener->addTag(MODULE_NAME); $filesOpener->save(); // Create: Close wrapper for Favicon Folder Name $filesCloser = new Field(); $filesCloser->type = new FieldtypeFieldsetClose(); $filesCloser->name = 'fmOpenFolderName' . FieldtypeFieldsetOpen::fieldsetCloseIdentifier; $filesCloser->label = "Close open fieldset"; $filesCloser->addTag(MODULE_NAME); $filesCloser->save(); // Create Favicon Folder Name $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeText"); $fmField->name = 'folderName'; $fmField->label = 'Favicon Folder:'; $fmField->description = $this->config->urls->files; $fmField->placeholder = 'Destination Folder for your generated favicons, webmanifest and browserconfig'; $fmField->columnWidth = 100; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon('folder'); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($tabOpener); $fmFieldgroup->add($filesOpener); $fmFieldgroup->add($fmField); $fmFieldgroup->add($filesCloser); $fmFieldgroup->add($tabCloser); $fmFieldgroup->save(); /////////////////////////////////////////////////////////////// // Experimental Markup Tests $wrapperFaviconMagic = new InputfieldWrapper(); $wrapperFaviconMagic->attr('id','faviconMagicWrapper'); $wrapperFaviconMagic->attr('title',$this->_('Favicon Magic')); // field show info what $field = $this->modules->get('InputfieldMarkup'); $field->name = 'use'; $field->label = __('How do I use it?'); $field->collapsed = Inputfield::collapsedNever; $field->icon('info'); $field->attr('value', 'Does this even begin to vaguely work?'); $field->columnWidth = 50; $wrapperFaviconMagic->add($field); $fmTemplate->fields->add($wrapperFaviconMagic); $fmTemplate->fields->save(); ///////////////////////////////////////////////////////////// // Create page $page = $this->wire( new Page() ); $page->template = MODULE_NAME; $page->parent = $this->wire('pages')->get('/'); $page->addStatus(Page::statusHidden); $page->title = 'Favicons'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } }  
    • By Sebi
      Since it's featured in ProcessWire Weekly #310, now is the time to make it official:
      Here is Twack!
      I really like the following introduction from ProcessWire Weekly, so I hope it is ok if I use it here, too. Look at the project's README for more details!
      Twack is a new — or rather newish — third party module for ProcessWire that provides support for reusable components in an Angular-inspired way. Twack is implemented as an installable module, and a collection of helper and base classes. Key concepts introduced by this module are:
      Components, which have separate views and controllers. Views are simple PHP files that handle the output for the component, whereas controllers extend the TwackComponent base class and provide additional data handling capabilities. Services, which are singletons that provide a shared service where components can request data. The README for Twack uses a NewsService, which returns data related to news items, as an example of a service. Twack components are designed for reusability and encapsulating a set of features for easy maintainability, can handle hierarchical or recursive use (child components), and are simple to integrate with an existing site — even when said site wasn't originally developed with Twack.
      A very basic Twack component view could look something like this:
      <?php namespace ProcessWire; ?> <h1>Hello World!</h1> And here's how you could render it via the API:
      <?php namespace Processwire; $twack = $modules->get('Twack'); $hello = $twack->getNewComponent('HelloWorld'); ?> <html> <head> <title>Hello World</title> </head> <body> <?= $hello->render() ?> </body> </html> Now, just to add a bit more context, here's a simple component controller:
      <?php namespace ProcessWire; class HelloWorld extends TwackComponent { public function __construct($args) { parent::__construct($args); $this->title = 'Hello World!'; if(isset($args['title'])) { $this->title = $args['title']; } } } As you can see, there's not a whole lot new stuff to learn here if you'd like to give Twack a try in one of your projects. The Twack README provides a really informative and easy to follow introduction to all the key concepts (as well as some additional examples) so be sure to check that out before getting started. 
      Twack is in development for several years and I use it for every new project I build. Also integrated is an easy to handle workflow to make outputs as JSON, so it can be used to build responses for a REST-api as well. I will work that out in one section in the readme as well. 
      If you want to see the module in an actual project, I have published the code of www.musical-fabrik.de in a repository. It runs completely with Twack and has an app-endpoint with ajax-output as well.
      I really look forward to hear, what you think of Twack🥳!
      Features Installation Usage Quickstart: Creating a component Naming conventions & component variants Component Parameters directory page parameters viewname Asset handling Services Named components Global components Ajax-Output Configuration Versioning License Changelog
    • By Robin S
      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/
×
×
  • Create New...