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 Macrura
      Field Descriptions Extended
      This module enables you to extend field descriptions by dividing short descriptions with a longer text that is revealed in a toggle.
      Modules Directory: http://modules.processwire.com/modules/field-descriptions-extended/
      Github: https://github.com/outflux3/FieldDescriptionsExtended
      Extending your field descriptions using the standard field's description field.
      Once this module is installed, it will automatically search your description field for the presence of 5 dashes (-----).
      Any content above the 5 dashes will be visible and the content below the dashes will be hidden. A 'More...' link will appear at the end of the short description which when clicked will reveal the rest of the description.
      Using Simple Markdown Editor with the description field
      If you have Simple Markdown Editor (InputfieldSimpleMDE) installed, you can enable the field description to have that editor.
      *When using Simple MDE, you can use the button (Insert Horizontal Line) instead of typing 5 dashes. More about SimpleMDE.
      Extending your field descriptions using content from a ProcessWire Page for the field description.
      You may use the content from a ProcessWire page as a field description. This would allow you to easily insert images, links, and use hanna codes.
      To use page content for your field descriptions, please follow these instructions:
      Install Select Fields module (FieldtypeFields) http://modules.processwire.com/modules/fieldtype-fields/ Create a new field using this field type, e.g. field_select. Add the field to any template you will be using for your field descriptions. Setup your help pages (for example under a settings branch) where you will store the field description content,using the template containing the Field Select. Add content to a page and select the field where that content should show. To show a short text before the link to the longer content, separate them with 5 dashes Be sure to update your settings on this page, first enable page content descriptions,then specify the name of the Select Fields field, template to search, and content field. If you create a field description using this method, please note that the description field must be blank for contexts where you want the page content to appear.
      You can freely use template context for field descriptions, but the Page Content method is not context sensitive and will display under all contexts where the description is blank.
      ----
      original post:
      This is a new module, hope to release soon, which allows extended field descriptions, in currently 2 ways.
      The main feature of the module is that you can have a short description and then a 'more...' link which drops down a longer block of text.
      This is achieved by separating the intro/visible text and the rest with 5 dashes.

      Example setup:

      the 2nd way is if you are using AdminThemeUiKit, you can show extended field instructions in a panel. The content of the panel is edited on a regular PW page. This use case would probably not be that common, but if you had a field that required some extended instructions for how to use, this could be useful; Also, since this allows you to target information and instructions down at the field level, it could reduce the amount of documentation needed on a global level, since it is a lot more context targeted.

    • By Robin S
      Breadcrumb Dropdowns
      Adds dropdown menus of page edit links to the breadcrumbs in Page Edit.

      Installation
      Install the Breadcrumb Dropdowns module. The module requires ProcessWire >= v3.0.83 and AdminThemeUikit.
      There is a checkbox option in the module config that determines if the breadcrumb dropdowns will include pages that the user does not have permission to edit.
      Features/details
      The module adds an additional breadcrumb item at the end for the currently edited page. That's because I think it's more intuitive for the dropdown under each breadcrumb item to show the item's sibling pages rather than the item's child pages. In the dropdown menus the current page and the current page's parents are highlighted in a crimson colour to make it easier to quickly locate them in case you want to edit the next or previous sibling page. If the option to include uneditable pages is selected then those pages are indicated by a reduced text opacity and the "not-allowed" cursor is shown on hover. There is a limit of 25 sibling pages per dropdown for performance reasons and to avoid the dropdown becoming unwieldy. Incompatibilities
      This module replaces the AdminThemeUikit::renderBreadcrumbs method so will potentially be incompatible with other modules that hook the same method.
       
      https://modules.processwire.com/modules/breadcrumb-dropdowns/
      https://github.com/Toutouwai/BreadcrumbDropdowns
    • By joshuag
      Hey guys, 
      Thought I would share a quick preview of Designme. A module we (Eduardo @elabx and I) are building for visually laying out your templates/edit screens. 🙂
      This is a really quick, zero polish screen grab. FYI. 
      Video #2 - UPDATE
      This new video shows the following features in Designme:
      Re-arranging fields via Drag & Drop Re-sizing fields via Dragging. Adjusting field settings - with live refresh. Working on "hidden" fields while Designme is active. Creating New fields. Deleting fields. Creating/Deleting Tabs. Dragging fields between tabs. Creating fieldsets. Tagging/Un-tagging fields. Fields without headers expand when hovered (like checkboxes). Live filtering of fields in the sidebar. Ability to adjust (all) Template settings without leaving Designme. Template File Tree Editing Template files source code with ACE Editor. Editing Multiple files with ACE Editor. (New Tabs) Saving files. Techie stuff Fields load their own js/css dependancies. *ready to use on creation (*most fields)  Everything happens via Ajax to ProcessPageEdit (via module + hooks). Designme has a JS api that you can use.  All actions trigger events.  We would love any detailed feedback on what you see so far. If you are interested in testing Designme. Let me know below. 🙂
       
       
      Video #1. 
       
    • By dreerr
      TemplateEnginePug (formally TemplateEngineJade)
       
      This module adds Pug templates to the TemplateEngineFactory. It uses https://github.com/pug-php/pug to render templates.
      doctype html html(lang='en') head meta(http-equiv='content-type', content='text/html; charset=utf-8') title= $page->title link(rel='stylesheet', type='text/css', href=$config->urls->templates . 'styles/main.css') body include header.pug h1= $page->title if $page->editable() p: a(href=$page->editURL) Edit Project on GitHub: github.com/dreerr/TemplateEnginePug
      Project in modules directory: modules.processwire.com/modules/template-engine-pug/
       
      For common problems/features/questions about the Factory, use the TemplateEngineFactory thread.
       
    • By tpr
      ProcessNetteTester
      Run Nette Tester tests within ProcessWire admin.
      (continued from here)

      Features
      AJAX interface for running Nette Tester tests, in bulk or manually display counter, error message and execution time in a table run all tests at once or launch single tests show formatted test error messages and report PHP syntax errors stop on first failed test (optional) hide passed tests (optional) display failed/total instead passed/total (optional) re-run failed tests only (optional) auto scroll (optional) include or exclude tests based on query parameters start/stop all tests with the spacebar reset one test or all tests (ctrl+click) https://modules.processwire.com/modules/process-nette-tester/
      https://github.com/rolandtoth/ProcessNetteTester