Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom fields are nor working #511

Closed
Schrijvers123 opened this issue Jan 8, 2020 · 15 comments
Closed

Custom fields are nor working #511

Schrijvers123 opened this issue Jan 8, 2020 · 15 comments
Assignees
Labels
bug

Comments

@Schrijvers123
Copy link

@Schrijvers123 Schrijvers123 commented Jan 8, 2020

Steps to reproduce the issue

Add your custom field to the module and place Field & Rules Path to Module.

afbeelding

Compile the module.

Goto the parameters of the module you will see the custom field is just a text box.

afbeelding

Looking into the module folder fields, there is no custom field. Looking in the admin area of my component, there I use the same field, I copied the custom field PHP to the fields section of the module. After that, the custom field is working.

SO it seems that the folders are created, but the proper files are not copied.

Expected result

Proper working custom field

Actual result

Only a textfield.

System information (as much as possible)

  • OS Name & Version: Windows 10
  • MySql Version: 5.7.24
  • Apache Version: Apache/2.4.35 (Win64) OpenSSL/1.1.1b PHP/7.2.19
  • PHP Version: 7.2.19
  • Joomla Version: 3.9.14
  • JCB Version: 2.10.9
  • Browser: Firefox

Additional comments

@Llewellynvdm Llewellynvdm self-assigned this Jan 25, 2020
@Llewellynvdm Llewellynvdm added the bug label Jan 25, 2020
@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Jan 25, 2020

Okay I found the bug, and it has been fixed. To patch until next release check out these changes.

@Schrijvers123

This comment has been minimized.

Copy link
Author

@Schrijvers123 Schrijvers123 commented Feb 10, 2020

@Llewellynvdm just checked it with beta version 2.10.11, it seems still not working. The necessary files (the custom field name) is not copied the module. I made a explaination movie. you can find it: https://vimeo.com/390569041/44de1da37f

@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Feb 10, 2020

Thanks for the video, I see that it is not copied. Yet the reason to why is still unclear.

Does the custom field belong to that components tables, and is build in the component? or to and external component? Since the module custom fields are only moved if they exist in the component.

So looking at the method called moveFieldsRules on line 1806 you will see that we check if the field was build, and if true then we move the field.

This limitation is due to the nature of how custom fields are build. They need the view and components information most of the time, and so without the actual view or component the custom field does not have enough info to be build. So that means if the custom field is related to another component or type named differently in the model as in the component, it will not be copied.

So I have been wondering about a workaround but have not implemented any yet. We need to almost force the user to hard code all the placeholders. So all these [[[view]]], ###ID###, ###TEXT###, ###TABLE###, [[[com_component]]], and ###CODE_TEXT### must have the actual values for the compiler to be able to build a custom field without the component and view/table it belongs to.

So I fixed the bug, the current limitation is an architectural one, and it is not easy to resolve. Do you have any ideas? and does this help you understand why it is not a bug?

@Llewellynvdm Llewellynvdm reopened this Feb 10, 2020
@Schrijvers123

This comment has been minimized.

Copy link
Author

@Schrijvers123 Schrijvers123 commented Feb 11, 2020

Do you check if the field is built in the backend of the frontend? My component is working on the backend (where the field excist), the modules on the frontend. Could this be the issue?

The field is built in the component builder and belongs to the component.

@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Feb 12, 2020

All custom fields get loaded from the back-end folder of fields so to avoid duplication in components. So there is just one place. Looking at the code you will see this:

if (JFile::exists($this->componentPath . '/admin/models/fields/' . $field['type_name'] . '.php'))
{
	// move the custom field
	JFile::copy($this->componentPath . '/admin/models/fields/' . $field['type_name'] . '.php', $path . '/fields/' . $field['type_name'] . '.php');
}

Then if the field is copied it is moved to the module folders, and this is also just one place.

Can I ask you to run some test? Step One: in the function moveFieldsRules add a var_dump($this->extentionCustomfields);jexit(); to see what fields were loaded as candidates for this purpose? Then compile the component and post the result here. Should the result be empty... then we will move deeper to step three.

Then step two remove the first code, and on line 1814 add var_dump('file was found');jexit(); and compile you component again. Then lets see if the file is found.

Step three is only needed if the first test resulted in an empty array. So before we go there, lets see what we find out with the above two steps.

@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Feb 12, 2020

You see the $this->extentionCustomfields is populated in one place line 3330 in the field class, so if it is empty and the field names are not listed, then we need to go to this area and look at what prevents the fields from being added. This will be the step three of our debugging effort 👍

So let me know what you found and we can take it from there.

@Schrijvers123

This comment has been minimized.

Copy link
Author

@Schrijvers123 Schrijvers123 commented Feb 12, 2020

The result:
Step 1:

array(2) {
	["traininggroupnames"]=> string(18) "traininggroupnames"
	["selecttraining"]=> string(14) "selecttraining"
}

Step 2: string(14) "file was found"

@Schrijvers123

This comment has been minimized.

Copy link
Author

@Schrijvers123 Schrijvers123 commented Feb 12, 2020

Step 3:
I added some trackin code to step 3:

// if this field gets used in plugin or module we should track it so if needed we can copy it over
if ((strpos($view_name_single, 'P|uG!n') !== false || strpos($view_name_single, 'M0dU|3') !== false) &&
	isset($data['custom']) && isset($data['custom']['type']))
{
	var_dump($data['type']);
	var_dump($data['custom']['type']);
	jexit();
	$this->extentionCustomfields[$data['type']] = $data['custom']['type'];
}

Th result is: string(18) "traininggroupnames" string(18) "traininggroupnames"

I hope this is helpfull

@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Feb 12, 2020

Well these results tell me the files are created, the array is loaded, and it should be copied to the module package. So can you confirm the the field type being targeted is in the array:

array(2) {
	["traininggroupnames"]=> string(18) "traininggroupnames"
	["selecttraining"]=> string(14) "selecttraining"
}

Then can you unzip the module and see if the file is in that package, before installation?

@Schrijvers123

This comment has been minimized.

Copy link
Author

@Schrijvers123 Schrijvers123 commented Feb 12, 2020

The situation is as follow. The component container several modules. Three of then contains the same custom field. They are called:

  1. mod_trainingorderform_v1_0_1__J3
  2. mod_traininglocations_v1_0_3__J3
  3. mod_trainingdatesandprices_v1_0_4__J3

File 1: contains the folder field and a file selecttraining.php is missing traininggroupnames.php
File 2: contains the folder field and a file traininggroupnames.php
File 3: contains the folder fields, but has no php file. e.g. is missing traininggroupnames.php

If I look to the behavour it looks like one the first complied files (file 2) containg traininggroupnames.php and by the next modules it's not added anymore. Are some values not reset?

You can see it in action on https://vimeo.com/391102698/a026f81287

@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Feb 13, 2020

Got it... I know what is the issue. Thank you @Schrijvers123 I will push out the fix later today. I will explain more later 👍

@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Feb 13, 2020

you can now test the latest staging branch and the issue should be resolved.

@Schrijvers123

This comment has been minimized.

Copy link
Author

@Schrijvers123 Schrijvers123 commented Feb 13, 2020

@Llewellynvdm it seems to be working thanks. On one module I'm expecting an issue that the custom field is not showed on the frondend. An other custom field (in same module). is showed in the config section of the module. Do I need something to add to my code?
the module van be found here. [mod_trainingorderform_v1_0_3__J3.zip]

@Llewellynvdm

This comment has been minimized.

Copy link
Member

@Llewellynvdm Llewellynvdm commented Feb 13, 2020

JCB only adds the fields to the module in a Joomla way, by adding the following to the config area:

<!-- default paths of basic fieldset points to the module -->
<fieldset name="basic" label="basic"
	addrulepath="/modules/mod_trainingorderform/rules"
	addfieldpath="/modules/mod_trainingorderform/fields"
>

This is what loads the fields and the rules. If you create xml forms that are not part of the config and you build your own forms these paths are still added. So if they don't load I must say I find it hard to understand why.

@Schrijvers123

This comment has been minimized.

Copy link
Author

@Schrijvers123 Schrijvers123 commented Feb 13, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.