segmentsRepository = $segmentsRepository; $this->fields = [ 'name' => new Field( 'mailpoet:segment:name', Field::TYPE_STRING, __('Segment name', 'mailpoet'), function () { return $this->getSegment()->getName(); } ), 'id' => new Field( 'mailpoet:segment:id', Field::TYPE_INTEGER, __('Segment ID', 'mailpoet'), function () { return $this->getSegment()->getId(); } ), ]; } public function getKey(): string { return self::KEY; } public function getFields(): array { return $this->fields; } public function load(array $args): void { $id = $args['segment_id']; $this->segment = $this->segmentsRepository->findOneById($args['segment_id']); if (!$this->segment) { // translators: %d is the ID. throw NotFoundException::create()->withMessage(sprintf(__("Segment with ID '%d' not found.", 'mailpoet'), $id)); } } public function pack(): array { $segment = $this->getSegment(); return ['segment_id' => $segment->getId()]; } public function getSegment(): SegmentEntity { if (!$this->segment) { throw InvalidStateException::create()->withMessage(__('Segment was not loaded.', 'mailpoet')); } return $this->segment; } }