Multi user selector (v9)

Hi!

I need to have “multi user selector” attribute on Express entity. With version 8 I’ve found this addon very helpful: https://github.com/a3020/multi_user_selector_attribute but I can’t get it work on version 9.

So I tried to make my own attribute type. I can easily make a form for it by using selectMultipleUsers helper function. But I couldn’t figure out how to save those values? Any advice?

I have created a Pull Request on that repo to fix the v9 issues - https://github.com/a3020/multi_user_selector_attribute/pull/5

One thing to note is that there is a core bug in the saving of legacy attributes so this package won’t work with PHP 8 until that is fixed - https://github.com/concretecms/concretecms/issues/10804

1 Like

Great, thanks! :+1: I ran in to that same error before, I didn’t realize it was because of a bug on core.

Sorry I’m little lost here, why is this legacy attribute? Is there another way to make new custom attribute type for multi user selector?

Based on the code I think it’s a Legacy Attribute because it doesn’t use Doctrine, it uses database queries.

There is information in the Documentation about adding Custom Attributes but I will admit I have not read it all so I’m not 100% sure how you would go about doing this - Overview :: Concrete CMS

Right, thanks!

There is a lot in that documentation, I think I’ll try to focus on what could be done with the Data Value Objects.

I was able to make v9 working multi user selector by looking at this package Mesuva has made: https://github.com/Mesuva/multiple_page_selector_attribute

I made changes to form and displaying values, and the value object is returning UserInfo objects instead of page.

  public function form()
  {
      $data = [];

      if (is_object($this->attributeValue)) {
          $users = $this->attributeValue->getValue()->getUsersData();

          foreach($users as $u) {
              $data[] = [
                  'uID' => $u->getUID(),
              ];
          }
      }

      $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
      $usfh = $app->make('helper/form/user_selector');
      echo $usfh->selectMultipleUsers('uID', $data);
  }
  public function getDisplayValue()
  {
      $value = $this->attributeValue->getValueObject();
      if ($value) {

          $userInfos = [];
          $users = $value->getUsers();

          foreach($users as $u) {
              $uID = $u->getUserID();
              $uEmail = $u->getUserEmail();
              $uUrl = \URL::to("/members/profile/view") . '/' . $uID;

              $userInfo = '<a href="' . $uUrl . '">' . $uEmail . '</a>';
              $userInfos[] = $userInfo;
          }

          return implode(', ', $userInfos);
      }

      return '';
  }