kongondo

Module: Matrix Fieldtype & Inputfield

Recommended Posts

Some more thoughts on this - I wonder if maybe it's just best to turn on output formatting - that should handle getting the language for the current user.

On an unrelated note, I noticed that each entry in the matrix is a full PageArray - is this necessary? I haven't looked into/thought through this, but it seems like a lot of info to have in memory when all we need is a single value with its relevant row and column page ids. Maybe the full PageArray is needed, or maybe it doesn't matter - just thought I'd ask :)

Share this post


Link to post
Share on other sites

Hi Adrian. Glad you found a solution.

10 hours ago, adrian said:

Not sure if you want to implement just like this, or whether you think it's worth adding a more complete ML solution.

I haven't looked at this module in a while. I will have a think.

10 hours ago, adrian said:

PS - what about changing "Row Label" to the title of the parent page of the first column. In my case I have a page branch of Years to control this column. It would be much nicer if this read "Years" or "Year". Would that work, or are there more things to consider?

Ditto :).

Share this post


Link to post
Share on other sites
7 hours ago, adrian said:

On an unrelated note, I noticed that each entry in the matrix is a full PageArray - is this necessary?

That's strange. Where did you see that? The module does not return Page or PageArrays anywhere . A single entry is a Matrix object (a WireData) and groups of entries are MatrixArray objects (WireArray). Maybe I haven't looked at this in a while but I am pretty sure about this :).

Share this post


Link to post
Share on other sites

Hey @kongondo - note the Page within each Matrix item. Each one of these contains a full reference to the current page. This comes from dumping $page->matrix_field

58de67f336206_ScreenShot2017-03-31at7_29_43AM.png.3bebfb53ba4d61ab004d09a691779876.png

 

Here is the dump of $rows and $columns from the export function. You can see that each row is a full PW page object.

58de6dbbe8f1d_ScreenShot2017-03-31at7_53_28AM.png.463af2d8871a92b23da4f19b82c30be3.png

Is this expected?

Share this post


Link to post
Share on other sites

@adrian,

Aah, my bad. The culprit is where I grab the respective row and column pages in order to get the friendly rowLabel and columnLabel respectively. Would uncacheAll do the trick (to clear memory)? If not I could get titles using raw SQL...

Thanks for catching this.

Share this post


Link to post
Share on other sites

Hey @kongondo - me again :)

I have another issue for you - I recently deleted a page that was driving the matrix rows (ie in the "data" field in the DB), but it didn't remove that row from the matrix table. Maybe this in intentional to prevent potential data loss, but it seems like there is no way of removing these without a manual SQL query to delete the appropriate entries from the DB. I am away from my computer the next couple of days and don't have time to test further right now, but please let me know if you have any trouble reproducing and I'll run some more tests.

Share this post


Link to post
Share on other sites

I'm trying to keep 'scores' for users on certain pages.  So far Matrix seems to do the job, as I can type a score for every user and for different assignments. 

What I'm trying to do now is to enter scores using the API, so *not* using the admin pages. 

If I understand things right, Matrix is simular to (or an instance of?) WireArray, so I should use $matrix->add(sth)?  I just can't find my way through. 

Does anyone have an example code snippet for entering values to a Matrix using the API?  It would help me a lot. 

 

edit: Of course I can always enter the data directly into the database, but I'd rather use the power of PW if possible. 

Share this post


Link to post
Share on other sites
On 2017-4-9 at 10:41 PM, adrian said:

I have another issue for you - I recently deleted a page that was driving the matrix rows (ie in the "data" field in the DB), but it didn't remove that row from the matrix table.

Thanks Adrian, I'll have a look.

On 2017-5-16 at 9:35 AM, longtom said:

Does anyone have an example code snippet for entering values to a Matrix using the API? 

Sorry for the late reply Longtom.  Here's a code snippet:

 

Share this post


Link to post
Share on other sites

Hi all. 

I am intending to ONLY support ProcessWire 3.x starting from the next version of this module. Please have a read here and let me know what you think. Thanks.

  • Like 1

Share this post


Link to post
Share on other sites

Hello @Kongodo and thanks for this module,

I am always in a hurry, and probably that is the reason why I still can't find right solution how to use this field.
Please can somebody write short instruction how to get this on attached image using this field?

Thanks.

 

opening-time.png

Share this post


Link to post
Share on other sites
12 hours ago, OLSA said:

Please can somebody write short instruction how to get this on attached image using this field?

The very, admittedly limited, docs are here.

Your days of the week are Matrix Rows. Your Open and Close are Matrix Columns. I suggest you create a parent page for both. So A Days of the Week page whose children are the Days themselves and something similar for Open and Close. Then use method 1 or 2 as described in the docs to populate your rows and columns. Alternatively, see method 3 which allows you to use multi pagefields.

  • Like 1

Share this post


Link to post
Share on other sites

All,

I intend to give this module some love soon. As part of this, I'm considering how to allow custom names for Columns and Rows (i.e. other than pages). 

  • Like 2

Share this post


Link to post
Share on other sites

Hello @kongondo

only a question: is it possible to use a special field of a page for the field of the matrix (fe a date field, an integer field,..)?

Share this post


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

Hello @kongondo

only a question: is it possible to use a special field of a page for the field of the matrix (fe a date field, an integer field,..)?

For storage, no, for reference, yes. Matrix stores a page ID for Row, a page ID for Column and a varchar for the value of the matrix (i.e. row-column = value). Using the page IDs of Row and Column, you can use PW API to get the page and hence, any field on that page.

Maybe not what you are after but thought to clarify anyway.

  • Thanks 1

Share this post


Link to post
Share on other sites

Hello @kongondo,

I have discovered a strange behavior:

I use a pagetable field inside a parent page. If click on the link inside the pagetable to open a child page inside a modal, I will be logged out from the system if the child page has a matrix field inside.

I have traced down the problem and it has to do with a hook that I run on the pagetable field of the parent page (inside my ready.php):

$wire->addHookBefore('InputfieldPageTable::render', function($event) {
   if($this->process != 'ProcessPageEdit') return;
   $table = $event->object;
   $page = $this->process->getPage();
   // event table   
   if(in_array($table->name, ['datespagetable', 'specialbusinesshourstable', 'eventspagetable', 'businessvacationpagetable'])) {
       if(count($page->children) == 0){          
           $table->notes = "";
            $this->buttonHook = $this->addHookAfter("InputfieldButton::render", null, function(HookEvent $event){
                $event->return = __("Here all dates will be shown afterwards if some were created.");
            });
      } 
      //this part of the button hook is responsible for loggin me out if I click on the link to the page inside the pagetable 
      else {
      $this->addHookBefore("InputfieldButton::render", null, function(HookEvent $event){      
         $button = $event->object;
         if($button->name == 'button'){
          $button->attr('value', __('Add event'));
         }
      });
} 
}
}); 

Inside this hook there is another hook for rendering the "Add new" button. So this "InputfieldButton::render" hook is responsible for loggin me out (if I remove this part everthing is fine).

So its not a big problem for me (I have comment it out), but maybe you have an idea, why these lines of code could lead to this behavior in combination with the matrix field.

Best regards

 

Share this post


Link to post
Share on other sites
19 hours ago, Juergen said:

but maybe you have an idea, why these lines of code could lead to this behavior in combination with the matrix field.

I'm totally clueless about this :lol:. I'll have to investigate, but it might not be soon, I'm afraid. I need to finish  work on some other module first, before I can turn my attention to Matrix.

Thanks for reporting.

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 Robin S
      Checkbox Reversed
      Modifies InputfieldCheckbox so that it shows the reverse of its true value. The checkbox will be unchecked when the field value is 1 and checked when the field value is not 1.
      Background
      The core FieldtypeCheckbox does not have a setting that allows a checkbox to be checked by default. One reason for this is that only a checked field saves a value to the database. An unchecked field does not save "0" to the database, but rather does not save any value for the field at all. Therefore there is no way to distinguish between a new field that has not yet been saved (and therefore could potentially get a default checked state) and a field that has deliberately been saved as unchecked.
      Because of this you sometimes have to use a checkbox in the opposite way than you would like. Suppose your client has requested a checkbox labelled "Bootylicious" that will be checked by default. This isn't possible with FieldtypeCheckbox so instead you have to convince them that a checkbox labelled "Not bootylicious" that is unchecked by default is just as good. This alternative will achieve the same thing, but it's not ideal.
      A solution
      This module doesn't change the limitations of the core checkbox field, but it provides a workaround that allows you to show the checkbox with the desired default state and label. So in the example above you would still name the field "not_bootylicious" (otherwise it could get confusing in your template files) but you can label the field "Bootylicious" and the checkbox will appear checked when its true value is actually unchecked, and vice versa. This allows new pages to show the checkbox checked by default. Clear as mud?
      Usage
      Install the Checkbox Reversed module.
      For any Checkbox field where you want the inputfield to show the reverse of its true value, activate the "Reverse the checked state of this inputfield?" option in the field settings.

       
      https://github.com/Toutouwai/CheckboxReversed
      http://modules.processwire.com/modules/checkbox-reversed/
    • By louisstephens
      I have been following @bernhard's great tutorial on creating a Dashboard and everything has very easy to understand so far. However, I need to add a select field that a template is using (so users can create a new page from the dashboard), but I am really at a complete lost on how to achieve this. I have been googling, but can't really find anything on the matter.
      $field = $this->modules->get('InputfieldSelect'); $field->name = "Select Manufacturer"; $field->findPagesSelector = "template=basic-page"; //not needed for select field $field->labelFieldName = "title"; $field->name = "Manufacturer Select"; $field->columnWidth = 34; $fieldset->add($field); I have the above code, which was originally an InputfieldPage, but since this is an options field, I have changed it. Has anyone actually gotten a select from a template (and its' values) in a module?
    • By Lex Sanchez
      Video or Social Post Embed
      Based on the TextformatterVideoEmbed module developed by Ryan Cramer, we have added the possibility to embed publications of the main social networks Facebook, Twitter and Instagram.
      ProcessWire Textformatter module that enables translation of YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu URLs to full embed codes, resulting in a viewable video or social post in textarea fields you apply it to.
      How to install
      Download or Clone from Github: https://github.com/lexsanchez/VideoOrSocialPostEmbed
      Copy the VideoOrSocialPostEmbed.module file to your /site/modules/ directory (or place it in /site/modules/VideoOrSocialPostEmbed/).
      Click check for new modules in ProcessWire Admin Modules screen. Click install for the module labeled: "Video or Social Post Embed".
      Now you will be on the module config screen. Please make note of the config options and set as you see fit.
      How to use
      Edit your body field in Setup > Fields (or whatever field(s) you will be placing videos in). On the details tab, find the Text Formatters field and select "Video or Social Post Embed". Save.
      Edit a page using the field you edited and paste in YouTube, Vimeo, Facebook, Twitter, Instagram and/or Issuu URLs each on their own paragraph.
      Example
      How it might look in your editor (like TinyMCE):
      How it works
      This module uses YouTube, Vimeo, Instagram, Facebook, Twitter and Issuu oEmbed services to generate the embed codes populated in your content. After these services are queried the first time, the embed code is cached so that it doesn't need to be pulled again.
      Configuration
      You may want to update the max width and max height settings on the module's configuration screen. You should make these consistent with what is supported by your site design.
      If you change these max width / max height settings you may also want to check the box to clear cache, so that YouTube/Vimeo/Facebook/Twitter/Instagram/Issuu oembed services will generate new embed codes for you.
      Using with Markdown, Textile or other LML
      This text formatter is looking for a YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu video URL surrounded by paragraph tags. As a result, if you are using Markdown or Textile (or something else like it) you want that text formatter to run before this one. That ensures that the expected paragraph tags will be present when VideoOrSocialPostEmbed runs. You can control the order that text formatters are run in by drag/drop sorting in the field editor.
      Copyright 2018 by Ryan Cramer / Updated by Lex Sanchez
    • By kixe
      Email Verification
      This module provides functions to validate email adresses and hosts. The module generates a textfile for blacklisted mailhosts (trashmail), which will be always up to date.
      Download
      https://modules.processwire.com/modules/email-verification/
      API
      // get module $mailcheck = $modules->get('EmailVerification'); // return bool/ string - automatted update of blacklist file $mailcheck->blacklisted(email|domain) // return bool - validate a top level domain, checks against IANA list $mailcheck->validTLD(tld) // return array of punycoded TLDs - cyclic updated, data pulled from IANA $mailcheck->getTLDs(cycle=2592000) // return bool - checks syntax converts to punycode $mailcheck->validDomainName(domain); // return bool - checks punycode encoded syntax $mailcheck->validHostName(host); // return bool - checks syntax and accessibility $mailcheck->validHost(email|domain) // add a single value to blacklist $mailcheck->addToBlacklist(email|domain) USAGE
      $mailcheck = $modules->get('EmailCheck'); $email = 'susi@trashmail.com'; if($mailcheck->blacklisted($email)) echo 'Email Provider not allowed'; if(!$mailcheck->validHost($email)) echo 'Mailhost not available'; Example blacklist file:  blacklist.txt