Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Define data-options@ from plugin config file

Started by Djordje 7 years ago · 1 replies · 632 views
7 years ago

Hi there!
I made a simple plugin to add some user information!
I want to make new blueprints on item.html.twig

This is plugin config file:

YAML
enabled: false
authors:
  -
    name: Author 1
    desc: Description 1
    custom_file:
      user/themes/quark/images/download.jpg:
        name: download.jpg
        type: image/jpeg
        size: 7134
        path: user/themes/quark/images/download.jpg
  -
    name: Author 2
    desc: Description 2
    custom_file:
      user/themes/quark/images/student-2.png:
        name: student-2.png
        type: image/png
        size: 172675
        path: user/themes/quark/images/student-2.png

This is a blueprints:

YAML
header.author:
   type: select
   label: Author
   classes: fancy
   data-options@: '\Grav\Plugin\AuthorsPlugin::getAuthors'

And I have this in plugin php file:

PHP
public static function getAuthors() {

        $author_name = $this->grav['config']->get('plugins.authors.name');

    }

I get Error:
Using $this when not in object context

Any solutions for this? Thanks!

7 years ago

Your function which returns a value to use as a dynamic field property needs to be a so called static function. As a consequence that function is not part of the other object oriented code and therefor $this can't be used.

Though I can't explain exactly why I can show you how to tackle this ;) as I had to cope with the same while developing the Form Prefiller Plugin.

Instead of $this->grav['config'] use Grav::instance()['config']

See for example the getTwig() function of that plugin.

👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 99 16 hours ago
General · by pamtbaau, 21 hours ago
1 63 20 hours ago
General · by Andy Miller, 1 day ago
0 48 1 day ago
General · by Marcel, 12 months ago
6 357 5 days ago
General · by Duc , 6 days ago
3 45 6 days ago