lookup = $lookup; $this->userOrAudience = $userOrAudience; } /** * @inheritDoc */ public function filterFromForm( $names ) { $names = trim( $names ); if ( $names !== '' ) { $names = preg_split( '/\n/', $names, -1, PREG_SPLIT_NO_EMPTY ); $ids = $this->getLookup()->centralIdsFromNames( $names, $this->userOrAudience ); if ( $ids ) { return implode( "\n", $ids ); } } // If the user list is empty, it should be null (don't save) rather than an empty string return null; } /** * @inheritDoc */ public function filterForForm( $value ) { $ids = self::splitIds( $value ); $names = $ids ? $this->getLookup()->namesFromCentralIds( $ids, $this->userOrAudience ) : []; return implode( "\n", $names ); } /** * Splits a newline separated list of user ids into an array. * * @param string $str * @return int[] */ public static function splitIds( $str ) { return array_map( 'intval', preg_split( '/\n/', $str, -1, PREG_SPLIT_NO_EMPTY ) ); } /** * @return CentralIdLookup */ private function getLookup() { $this->lookup = $this->lookup ?? CentralIdLookup::factory(); return $this->lookup; } }