/** * Displays a list of available payment types. * * @return array * A render array. */ public function execute() { $table = ['#empty' => $this->t('There are no available payment types.'), '#header' => [$this->t('Type'), $this->t('Description'), $this->t('Operations')], '#type' => 'table']; $definitions = $this->paymentTypeManager->getDefinitions(); unset($definitions['payment_unavailable']); foreach ($definitions as $plugin_id => $definition) { $operations_provider = $this->paymentTypeManager->getOperationsProvider($plugin_id); $operations = $operations_provider ? $operations_provider->getOperations($plugin_id) : []; // Add the payment type's global configuration operation. $operations['configure'] = ['url' => new Url('payment.payment_type', ['bundle' => $plugin_id]), 'title' => $this->t('Configure')]; // Add Field UI operations. if ($this->moduleHandler->moduleExists('field_ui')) { if ($this->currentUser->hasPermission('administer payment fields')) { $operations['manage-fields'] = ['title' => $this->t('Manage fields'), 'url' => new Url('entity.payment.field_ui_fields', ['bundle' => $plugin_id])]; } if ($this->currentUser->hasPermission('administer payment form display')) { $operations['manage-form-display'] = ['title' => $this->t('Manage form display'), 'url' => new Url('entity.entity_form_display.payment.default', ['bundle' => $plugin_id])]; } if ($this->currentUser->hasPermission('administer payment display')) { $operations['manage-display'] = ['title' => $this->t('Manage display'), 'url' => new Url('entity.entity_view_display.payment.default', ['bundle' => $plugin_id])]; } } $table[$plugin_id]['label'] = ['#markup' => $definition['label']]; $table[$plugin_id]['description'] = ['#markup' => isset($definition['description']) ? $definition['description'] : NULL]; $table[$plugin_id]['operations'] = ['#links' => $operations, '#type' => 'operations']; } return $table; }
/** * @covers ::render */ public function testRender() { $plugin_id = $this->randomMachineName(); $plugin_label = $this->randomMachineName(); $plugin_definition = ['label' => $plugin_label]; $this->paymentTypeManager->expects($this->atLeastOnce())->method('getDefinition')->with($plugin_id)->willReturn($plugin_definition); $result_row = new ResultRow(); $result_row->{$this->sut->field_alias} = $plugin_id; $this->assertSame($plugin_label, $this->sut->render($result_row)); }
/** * {@inheritdoc} */ public function create(array $values = []) { /** @var \Drupal\payment\Entity\PaymentInterface $payment */ $payment = parent::create($values); $payment_type = $this->paymentTypeManager->createInstance($values['bundle']); $payment_type->setPayment($payment); $payment->get('payment_type')->setValue($payment_type); $status = $this->paymentStatusManager->createInstance('payment_created')->setCreated(time()); $payment->setPaymentStatus($status); return $payment; }
/** * @covers ::execute */ public function testExecute() { $definitions = ['foo' => ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName()], 'bar' => ['label' => $this->randomMachineName()], 'payment_unavailable' => []]; $operations_foo = ['baz' => ['title' => $this->randomMachineName()]]; $operations_provider_foo = $this->getMock(PluginOperationsProviderInterface::class); $operations_provider_foo->expects($this->once())->method('getOperations')->with('foo')->willReturn($operations_foo); $this->paymentTypeManager->expects($this->once())->method('getDefinitions')->willReturn($definitions); $map = [['foo', $operations_provider_foo], ['bar', NULL]]; $this->paymentTypeManager->expects($this->exactly(2))->method('getOperationsProvider')->willReturnMap($map); $this->moduleHandler->expects($this->any())->method('moduleExists')->with('field_ui')->willReturn(TRUE); $map = [['administer payment fields', TRUE], ['administer payment form display', TRUE], ['administer payment display', TRUE]]; $this->currentUser->expects($this->atLeastOnce())->method('hasPermission')->willReturnMap($map); $build = $this->sut->execute(); $expected_build = ['#empty' => 'There are no available payment types.', '#header' => ['Type', 'Description', 'Operations'], '#type' => 'table', 'foo' => ['label' => ['#markup' => $definitions['foo']['label']], 'description' => ['#markup' => $definitions['foo']['description']], 'operations' => ['#links' => $operations_foo + ['configure' => ['url' => new Url('payment.payment_type', ['bundle' => 'foo']), 'title' => 'Configure'], 'manage-fields' => ['title' => 'Manage fields', 'url' => new Url('entity.payment.field_ui_fields', ['bundle' => 'foo'])], 'manage-form-display' => ['title' => 'Manage form display', 'url' => new Url('entity.entity_form_display.payment.default', ['bundle' => 'foo'])], 'manage-display' => ['title' => 'Manage display', 'url' => new Url('entity.entity_view_display.payment.default', ['bundle' => 'foo'])]], '#type' => 'operations']], 'bar' => ['label' => ['#markup' => $definitions['bar']['label']], 'description' => ['#markup' => NULL], 'operations' => ['#links' => ['configure' => ['url' => new Url('payment.payment_type', ['bundle' => 'bar']), 'title' => 'Configure'], 'manage-fields' => ['title' => 'Manage fields', 'url' => new Url('entity.payment.field_ui_fields', ['bundle' => 'bar'])], 'manage-form-display' => ['title' => 'Manage form display', 'url' => new Url('entity.entity_form_display.payment.default', ['bundle' => 'bar'])], 'manage-display' => ['title' => 'Manage display', 'url' => new Url('entity.entity_view_display.payment.default', ['bundle' => 'bar'])]], '#type' => 'operations']]]; $this->assertEquals($expected_build, $build); }
/** * @covers ::title */ public function testTitle() { $plugin_id = $this->randomMachineName(); $label = $this->randomMachineName(); $definition = ['label' => $label]; $this->paymentTypeManager->expects($this->once())->method('getDefinition')->with($plugin_id)->willReturn($definition); $this->assertSame($label, $this->sut->title($plugin_id)); }
/** * Gets the title of the payment type configuration page. * * @param string $bundle * The payment type's plugin ID. * * @return string */ public function title($bundle) { $definition = $this->paymentTypeManager->getDefinition($bundle); return $definition['label']; }
/** * {@inheritdoc} */ public function render(ResultRow $values) { $plugin_id = $this->getValue($values); $plugin_definition = $this->paymentTypeManager->getDefinition($plugin_id); return $plugin_definition['label']; }