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

[Feature Request] link() helper on CrudColumn and certain CrudFields #8

Closed
selected-pixel-jameson opened this issue Jun 17, 2020 · 9 comments

Comments

@selected-pixel-jameson
Copy link

Feature Request

What's the feature you think Backpack should have?

Backpack just implemented the relationship option for ajax selects and multiple selects. It would be nice to have a property in these select fields along the lines of 'hyperlink => true', which would make the items that are listed out clickable and would allow the user to navigate to that specific model's CRUD Controller to edit / view that item by clicking on it.

Right now our clients ask for this all the time and we end up building out custom templates for this which is a lot of work and renders a large feature of backpack pretty useless for us because of a smaller requirement.

Have you already implemented a prototype solution, for your own project?

No

Do you see this as a core feature or an add-on?

Core Feature

@tabacitu tabacitu changed the title [Feature Request] [Feature Request] link() helper on CrudField Jun 18, 2020
@tabacitu tabacitu changed the title [Feature Request] link() helper on CrudField [Feature Request] link() helper on CrudColumn and certain CrudFields Jun 18, 2020
@tabacitu
Copy link
Member

tabacitu commented Jun 18, 2020

Totally agree. It was talked about when we first launched 4.[2]1, but we haven't gotten to it (yet).

The way I see it, it would be link() or linkTo() or linksTo(), not hyperlink() which is longer and rarely used, I think. And the parameter would be probably be the Controller it would point to (or Model, whichever is actually needed to achieve this).

So for Columns you'd be able to do:

// if we need it to point to the CrudController
CRUD::column('category')->link(\App\Http\Controllers\Admin\CategoryCrudController::class);
CRUD::column('category')->linkTo(\App\Http\Controllers\Admin\CategoryCrudController::class);
CRUD::column('category')->linksTo(\App\Http\Controllers\Admin\CategoryCrudController::class);

// if we need it to point to the Model
CRUD::column('category')->link(\App\Models\Category::class);

// actually if what we need is the model (unlikely) we can probably guess it from the field, so it would be
CRUD::column('category`)->link(); 
// or
CRUD::column('category`)->withLinks(); 

After writing this I've realised you mentioned FIELDS not COLUMNS - and I guess we can do that for the relationship field too, indeed. Though it should probably open the link in a new tab there, to prevent the unwanted situation where the admin edits something, clicks a link to a related item, then loses all their changes.

--

Thanks for raising this @selected-pixel-jameson - it's indeed a feature that will probably help out a lot. I've prioritised it so we get it done within 4.1 as a non-breaking change.

Cheers!

@tabacitu
Copy link
Member

In terms of implementation, I see this as a convenience method on CrudColumn, just like size() on the CrudField class. It wouldn't be an attribute per-se, but a convenience method that helps set the:

  • wrapper[element] to a;
  • wrapper[href] to the route to the show method for that particular entry;

@pxpm
Copy link

pxpm commented Jun 18, 2020

@tabacitu atm our wrapper wraps the field itself, to accomodate this we must change wrapper implementation as we did in columns to be in every selected entry instead of the whole field.

@tabacitu
Copy link
Member

giphy

😭 Ok then.

I definitely think we should automate it for columns with a link() - that's what a developer wants 99% of the time.

I don't know about fields, then... Will think about it... My first thought is that it's not worth rewriting the wrapper feature for this little. Not sure people actually want to open the related entry from the Create / Update form... (@selected-pixel-jameson please correct me if I'm wrong).

@pxpm
Copy link

pxpm commented Jun 26, 2020

Technically in columns we already have the option to open each individual selected entry with their own anchor, so clicking it would render whatever link developer wants.

From what I see, this link() helper would be a replace for wrapper, so why not use wrapper() instead ?

@tabacitu
Copy link
Member

@pxpm in columns, that's what link() should do behind the scenes - set the wrapper to an anchor with a href pointing to that entry's Show operation. It'd be just for convenience, instead of having to write:

                CRUD::column('category`)->wrapper([
                    'href' => function ($crud, $column, $entry, $related_key) {
                        return backpack_url('category/'.$related_key.'/show');
                    },
                ]);

you'd write:

                CRUD::column('category`)->link();
                // or
                CRUD::column('category`)->withLinks();
                // or
                CRUD::column('category`)->withLinksToShow();
                // or
                CRUD::column('category`)->linkToShow();

Or something like that, I'm not sure what the best name would be.

@tabacitu tabacitu transferred this issue from Laravel-Backpack/CRUD Jul 25, 2020
@tabacitu tabacitu moved this to No Status in Backpack v5.3 May 3, 2022
@tabacitu tabacitu moved this from No Status to Todo in Backpack v5.3 May 3, 2022
@tabacitu tabacitu removed their assignment Aug 9, 2022
@tabacitu tabacitu removed this from Backpack v5.3 Nov 14, 2022
@tabacitu
Copy link
Member

tabacitu commented Sep 4, 2023

@karandatwani92 let's do a prototype for:

CRUD::column('category')->linkTo('category.show'); // note that this is the ROUTE NAME, not OPERATION NAME

We might also add a helper (macro) for ease of use:

CRUD::column('category')->linkToShow(); that points to route('monster.show', $id) if that route exists.

But not in the prototype. Let's remember to also test this on morph relationships.

@karandatwani92
Copy link

PR Laravel-Backpack/CRUD#5317

@karandatwani92 karandatwani92 moved this from In Progress to Needs Testing, Review or Docs in This week Sep 13, 2023
@karandatwani92 karandatwani92 moved this from Todo to Needs Review in Backpack v6.x (July 2023-Feb 2024) Sep 13, 2023
@tabacitu tabacitu assigned karandatwani92 and unassigned tabacitu Sep 29, 2023
@tabacitu tabacitu moved this from Needs Review to In Progress in Backpack v6.x (July 2023-Feb 2024) Sep 29, 2023
@tabacitu tabacitu moved this from Needs Testing, Review or Docs to In Progress in This week Sep 29, 2023
@pxpm
Copy link

pxpm commented Oct 30, 2023

3 years later and we got it. 🙏 🥳
PR: Laravel-Backpack/CRUD#5317
DOCS: Laravel-Backpack/docs#519

Reviewed. will be released in the next couple hours. We can safely close this, it's on next Backpack version: 6.2.5

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

No branches or pull requests

4 participants