Jump to content

[Solved] Related pages list in Admin area


encho
 Share

Recommended Posts

To explain my problem, I will show my usecase scenario first.

I have the following page types:

  • There is a page type 'Person', with parent type 'People'
  • There is a page type 'Project' with parent type 'Projects'
  • 'People' and 'Projects' are just containers/parent pages to 'Person' and 'Project' respectively.

Every person can be associated with one or more projects, every project can have multiple people in charge.

What I did is - I made it 'Person'-centric, meaning I added a field on 'Person' type page that helps you select projects (Multi Page reference field). I didn't do the same for 'Project' type as it seems like duplicating the effort.

Result is when I edit a Person, I can see the projects associated and that is fine. What I want is when editing a Project to see what 'Person'(s) have that particular project in their admin page. I am talking about admin pages only, obviously this is much easier in frontend where I can do this via custom PHP code.

Maybe there is a Processwire field that can display a result of page selector?

Please advise on the above, I am open to alternative approaches to this problem as well. Thanks in advance!

 

Link to comment
Share on other sites

3 hours ago, encho said:

obviously this is much easier in frontend where I can do this via custom PHP code.

Adding custom PHP code to any page in the backend is extremely easy as well (if you know how) ? 

<?phhp
// in site/ready.php
$wire->addHookAfter("ProcessPageEdit::buildForm", function ($event) {
  $form = $event->return;
  $page = $event->object->getPage();
  if ($page->template != 'home') return;

  $existingField = $form->get('title');

  $out = "Show 5 random pages:";
  $pages = $this->wire->pages->find("limit=5, template=basic-page, sort=random");
  foreach ($pages as $p) {
    $out .= "<div><a href={$p->editUrl}>{$p->title}</a></div>";
  }

  $newField = [
    'type' => 'markup',
    'label' => 'foo',
    'icon' => 'check',
    'value' => $out,
  ];

  $form->insertAfter($newField, $existingField);
});

3zeWZvp.png

  • Like 3
Link to comment
Share on other sites

  • 3 weeks later...
  • encho changed the title to [Solved] Related pages list in Admin area

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
 Share

×
×
  • Create New...