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

Component view is using field clones not a reference. #22115

Closed
artur-stepien opened this issue Sep 10, 2018 · 5 comments
Closed

Component view is using field clones not a reference. #22115

artur-stepien opened this issue Sep 10, 2018 · 5 comments

Comments

@artur-stepien
Copy link
Contributor

Steps to reproduce the issue

Create template overrides for com_contact.
Go to /templates/yourtheme/com_contact/contact/default_form.php
Try to update field attribute by putting after this:

<?php foreach ($fields as $field) : ?>

following code:

/* @var $field FormField */
$name = $field->getAttribute('name');
$this->form->setFieldAttribute($name, 'hint', $field->getAttribute('label'));

Now create new contact and create a new menu item for it.
Go to front end and look at the message form.

Expected result

Each text field should have a placeholder attribute same as field label (the code above just uses field label to set text field placeholder).

Actual result

Nothing changes.

System information (as much as possible)

Joomla 3.8.12

Additional comments

It looks like on the way to view form fields lose reference. That way it is impossible to update field attributes from inside the view. It leads to dirty workarounds like str_ireplace etc. It worked previously but I'm not sure in which version it started failing. There is still possibility to override form fields layouts for com_contact but that feels like overkill for simple attribute change.

@SharkyKZ
Copy link
Contributor

I think your code is incorrect. You are modifying the form but the field is already assigned to a variable. So you either need to have two loops, one for modifying the form and one for rendering the fields, or use $this->form->renderField() instead of $field->renderField().

@ghost
Copy link

ghost commented Sep 11, 2018

Comment above by @SharkyKZ isn't shown in issue Tracker.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22115.

@joomla-cms-bot
Copy link

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/22115

@artur-stepien
Copy link
Contributor Author

@SharkyKZ I know how to make a workaround but its pointless. Objects should be returned as reference. Not a clone. 2 loops requirement is the result of issue, not a cure. Its no critical but its still a bug.

@ggppdk
Copy link
Contributor

ggppdk commented Dec 29, 2018

Ok 1 way of achieve setting the attribute (as mentioned by @SharkyKZ) are

$this->form->setFieldAttribute($field->fieldname, 'hint', $field->getAttribute('label'));
echo $this->form->renderField($field->fieldname, $field->group);

Another way (instead of str_replace) is to do

$field->__set('hint', $field->getAttribute('label'));
echo $field->renderField();

but why some place are using

$this->form->renderField('somefieldname');

and other are using
$field->renderField() ?

why not use everywhere ?

$this->form->renderField($field->fieldname, $field->group);

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

No branches or pull requests

5 participants