Jump to content
MichaMichaMicha

Change field description in context via API

Recommended Posts

I've really tried my best but seems like I'm not able to change a fields description text in context of a template via the api.

$template->fieldgroup->title->description = "This should be the description";
$template->fieldgroup->title->save();
$template->fieldgroup->save();

Anybody having the same problem?

Note: if that works I also want to change the description in different languages, but that should not be a problem.

Share this post


Link to post
Share on other sites

Something like this should work...

$t = $templates->get('basic-page');//get the template
$f = $t->fieldgroup->getField('summary', true);//get the field in context of this template
$f->description = "This should be the description";//value of the field
$fields->saveFieldgroupContext($f, $t->fieldgroup);//save new setting in context

Edited for clarity...
In this example, we are changing the description of the field 'summary' in the context of the template 'basic-page'.

Edited by kongondo
  • Like 9

Share this post


Link to post
Share on other sites

Works, and the following code should set the label in different languages (in combination with the code kongondo posted). 

$english = $languages->get("english")->id;
$f->set("label{$english}","Date");
  • Like 2

Share this post


Link to post
Share on other sites

I just had to fiddle around with that.

It might be important to note that if you apply ANY field setting via $fields->saveFieldgroupContext all other field settings are copied over to the contextual settings as well.

So if you only set columnWidth the title (and all others) is copied over too. If you change the original non-contextual title, the old title stays in the fieldgroup context.

I wish the behavior would be like merging values, so when I change columnWidth only, all other values are taken on the fly from the non-contextual field settings when requested.

Share this post


Link to post
Share on other sites

the solution provided here did not work for me! i'm using pw 3.0.36 and this worked and is even easier :)

$fg = new Fieldgroup();
$fg->name = 'rocksvns';
$fg->add($this->fields->get('title'));
$fg->add($this->fields->get('rocksvn_version'));
$fg->save();

// set version field visible for this template
$fg->setFieldContextArray($this->fields->get('rocksvn_version')->id, array(
    'collapsed' => 0,
));
$fg->saveContext();

$t = new Template();
$t->name = 'rocksvns';
$t->fieldgroup = $fg;
$t->save();

tracy helped a lot here again :)

2016-10-24 13_39_28-Edit Template_ rocksvns • sandbox.dev.png

  • Like 4

Share this post


Link to post
Share on other sites

Stupid question: is it possible to include markup in a field description?

I'd like to add a simple modal link as cross-reference (sort of a cheatsheet). Tried it via API as well, but no dice.

<p class="description">
	<a href="foo/client-list/" class="pw-modal pw-modal-large ui-corner-all">Open client list</a>
</p>

Any other methods? A hook?

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.

×
×
  • Create New...