eZ Community » Forums » eZ Publish 5 Platform » Developing FieldType with parameters
expandshrink

Developing FieldType with parameters

Developing FieldType with parameters

Tuesday 14 May 2013 4:37:41 pm - 4 replies

Hello. Still trying to learn a bit more about ez5 and the migration extension process. 

Actually i'm trying to do an ez5 version of ezdisqus, an extension that can be reached at bdunogier's github account

https://github.com/bdunogier/ezdisqus

Following how other fieldtypes are built and the doc at https://confluence.ez.no/display/EZP/Legacy+configuration, i've got now a fromHash function and also a disqus.yml file with this piece of content

parameters:
    disquscomments.my_front_site.Disqus.ShortName: mysite  

My question is how should i proceed to get this value? Can this value be reached from FieldType class or maybe should i add a controller,  and call it from the fieldtype twig template?

Thank you!

 

Modified on Tuesday 14 May 2013 4:46:40 pm by Carlos Revillo

Tuesday 14 May 2013 4:48:18 pm

Hi Carlos

I'm not sure I understood your question happy.gif Emoticon. Could you please be more precise ?

Tuesday 14 May 2013 5:07:10 pm

i'll try to be more clear. 

In my Resources/config/ folder, i've added a disqus.yml. in this file i plan to add the settings, al least some of theme, that we had in https://github.com/bdunogier/ezdisqus/blob/master/settings/disqus.ini

Further more, i added a filled called Type.php in [Mybundle]/Core/FieldType/DisqusComments/Type.php. 

In this file, among others there's a function called toHash. (not fromHash as i said before, sorry.).

This toHash function is more or less like

public function toHash( $value )
{        
    if ( $this->isEmptyValue( $value ) )        
    {            
          return null;        
    }        
 
    return array(
        'comments_enabled' => $value->comments_enabled,
        'shortname' => // should i try to get the value i added in my disqus.yml?,
        'url' => // should i try to get the location having this fieldtype
);    }

I can get that comments_enabled value without any problems. but i wonder if:

1) Is a good idea try to get my DisqusShortName from this function, so in my disqus.html.twig i could go like

{% block disquscomments_field %}
...
{{ field.value.shortname }}
{% endblock %}

1. a) If so, how should i proceed?

1. b) If not, could be an idea to add a controller to my bundle and maybe calleid from my disqus.html.twig file where i will have something like

{% block disquscomments_field %}
{{ render( controller... }}
{% endblock %} 

Thanks!

Modified on Tuesday 14 May 2013 5:11:19 pm by Carlos Revillo

Thursday 23 May 2013 11:06:12 am

@Carlos You can always use the dependency injection configuration to insert parameters to your FieldType, something like this:

https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Bundle/EzPublishCoreBundle/Resources/config/fieldtypes.yml#L363

This way, your datatype does not need to know anything about service container or configuration. Everything is provided to it through the constructor.

Thursday 23 May 2013 11:18:29 am

Yep. Now i realize i can do that happy.gif Emoticon. Still learning all the symfony posiblities. Thank you!

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from