Trying to make a navigation link extension but can't use my newly added fields in my twig function.

edster - 4 months ago

In my twig macro I am trying to use link.mega or link.getMega(), neither are returning anything but null.

In my Extension.php file I have

**
     * This extension provides the TEXT
     * link type for the Navigation module.
     *
     * @var string
     */
    protected $provides = 'anomaly.module.navigation::link_type.text';

    /**
     * Return the entry title.
     *
     * @param  LinkInterface $link
     * @return string
     */
    public function title(LinkInterface $link)
    {
        return $link->getEntry()->getTitle();
    }

    /**
     * Return the entry mega bool.
     *
     * @param  LinkInterface $link
     * @return string
     */
    public function mega(LinkInterface $link)
    {
        return $link->getEntry()->getMega();
    }

    /**
     * Return the entry break bool.
     *
     * @param  LinkInterface $link
     * @return string
     */
    public function break(LinkInterface $link)
    {
        return $link->getEntry()->getBreak();
    }

    /**
     * Return the form builder for
     * the link type entry.
     *
     * @return FormBuilder
     */
    public function builder()
    {
        return app(TextNavTypeFormBuilder::class);
    }

However, if I use ** * This extension provides the TEXT * link type for the Navigation module. * * @var string */ protected $provides = 'anomaly.module.navigation::link_type.text'; /** * Return the entry title. * * @param LinkInterface $link * @return string */ public function title(LinkInterface $link) { return $link->getEntry()->getTitle(); } /** * Return the entry mega bool. * * @param LinkInterface $link * @return string */ public function mega(LinkInterface $link) { return $link->getEntry()->getMega(); } /** * Return the entry break bool. * * @param LinkInterface $link * @return string */ public function break(LinkInterface $link) { return $link->getEntry()->getBreak(); } /** * Return the form builder for * the link type entry. * * @return FormBuilder */ public function builder() { return app(TextNavTypeFormBuilder::class); } in the title function, I get the value I am looking for. Any help on what I am prob missing? I have tried extending bot h the dd($link->getEntry()->getMega()); and the LinkInterface in trying to figure it out but didn't get anywhere.

ryanthompson - 4 months ago

Have you tried {{ link.entry.mega }} or something similar? Use {{ dd($var) }} to figure out what you are getting in the view.

edster - 4 months ago

No I didn't try it with entry, didn't. Think I needed to as I assumed it wouldn't need entry as title / url etc were all link.something.

Ill give it a go as soon as I can this morning. I tried to dd(link) bit couldn't find the e try in there which is why I am assuming I cant find it.

edster - 4 months ago

So it shows up in the relations

LinkPresenter {#3611 ▼
  #object: LinkModel {#3156 ▼
    #ttl: 99999
    #active: false
    #current: false
    #with: array:2 [▶]
    #table: "navigation_links"
    #titleName: "id"
    #rules: array:7 [▶]
    #fields: array:7 [▶]
    #dates: array:3 [▶]
    #relationships: array:4 [▶]
    #stream: StreamModel {#3139 ▶}
    #translationForeignKey: "entry_id"
    #searchable: false
    +timestamps: false
    #translatedAttributes: []
    #guarded: []
    #titleKey: "id"
    #observables: array:4 [▶]
    #cascades: []
    #cache: []
    #connection: null
    #primaryKey: "id"
    #keyType: "int"
    #perPage: 15
    +incrementing: true
    #attributes: array:14 [▶]
    #original: array:14 [▶]
    #relations: array:3 [▼
      "entry" => TextNavTypeModel {#3533 ▼
        #searchable: false
        #table: "text_nav_type_title"
        #titleName: "title"
        #rules: array:4 [▶]
        #fields: array:4 [▶]
        #dates: array:2 [▶]
        #relationships: []
        #stream: StreamModel {#3499 ▶}
        #translationForeignKey: "entry_id"
        +timestamps: false
        #translatedAttributes: []
        #ttl: false
        #guarded: []
        #titleKey: "id"
        #observables: array:4 [▶]
        #cascades: []
        #cache: []
        #connection: null
        #primaryKey: "id"
        #keyType: "int"
        #perPage: 15
        +incrementing: true
        #attributes: array:10 [▶]
        #original: array:10 [▼
          "id" => 1
          "sort_order" => 1
          "created_at" => "2017-02-06 18:14:42"
          "created_by_id" => 1
          "updated_at" => null
          "updated_by_id" => null
          "title" => "Mega Menu!"
          "description" => null
          "mega" => 1
          "break" => 0
        ]
        #relations: []
        #hidden: []
        #visible: []
        #appends: []
        #fillable: []
        #dateFormat: null
        #casts: []
        #touches: []
        #with: []
        +exists: true
        +wasRecentlyCreated: false
      }
      "allowedRoles" => RoleCollection {#3557 ▶}
      "children" => LinkCollection {#3588 ▼
        #items: array:3 [▼
          2 => LinkPresenter {#4259 ▶}
          5 => LinkPresenter {#4379 ▶}
          8 => LinkPresenter {#4378 ▶}
        ]
      }
    ]
    #hidden: []
    #visible: []
    #appends: []
    #fillable: []
    #dateFormat: null
    #casts: []
    #touches: []
    +exists: true
    +wasRecentlyCreated: false
    #forceDeleting: false
  }
  #protected: array:3 [▶]
}