getOperations example

if ($update_tree_access->isAllowed()) {
        $form['terms'][$key]['weight'] = [
          '#type' => 'weight',
          '#delta' => $delta,
          '#title' => $this->t('Weight for added term'),
          '#title_display' => 'invisible',
          '#default_value' => $term->getWeight(),
          '#attributes' => ['class' => ['term-weight']],
        ];
      }

      if ($operations = $this->termListBuilder->getOperations($term)) {
        $form['terms'][$key]['operations'] = [
          '#type' => 'operations',
          '#links' => $operations,
        ];
      }

      if ($parent_fields) {
        $form['terms'][$key]['#attributes']['class'][] = 'draggable';
      }

      // Add classes that mark which terms belong to previous and next pages.

  protected function buildOperations(ConfigMapperInterface $mapper) {
    // Retrieve and sort operations.     $operations = $mapper->getOperations();
    uasort($operations, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
    $build = [
      '#type' => 'operations',
      '#links' => $operations,
    ];
    return $build;
  }

}
->with('configurable_language')
      ->willReturn($entity_type);

    $result = $this->configEntityMapper->getTypeLabel();
    $this->assertSame('test', $result);
  }

  /** * Tests ConfigEntityMapper::getOperations(). */
  public function testGetOperations() {
    $result = $this->configEntityMapper->getOperations();

    $expected = [
      'list' => [
        'title' => 'List',
        'url' => Url::fromRoute('config_translation.entity_list', ['mapper_id' => 'configurable_language']),
      ],
    ];

    $this->assertEquals($expected$result);
  }

}

  public function buildHeader() {
    $header['label'] = $this->t('Label');
    return $header + parent::buildHeader();
  }

  /** * {@inheritdoc} */
  public function getOperations(EntityInterface $entity) {
    $operations = parent::getOperations($entity);
    foreach (array_keys($operations) as $operation) {
      // This is a translation UI for translators. Show the translation       // operation only.       if (!($operation == 'translate')) {
        unset($operations[$operation]);
      }
    }
    return $operations;
  }

  /** * {@inheritdoc} */
/** * Load entity operations from the list builder. * * @return array * An array of operations. */
  protected function getListBuilderOperations() {

    if (is_null($this->listBuilderOperations)) {
      $this->listBuilderOperations = $this->entityTypeManager
        ->getListBuilder($this->getEntity()->getEntityTypeId())
        ->getOperations($this->getEntity());
    }

    return $this->listBuilderOperations;
  }

  /** * {@inheritdoc} */
  public function getOperations(): array {
    return $this->getListBuilderOperations();
  }

  

    else {
      $row['access']['data']['#markup'] = t('never');
    }
    return $row + parent::buildRow($entity);
  }

  /** * {@inheritdoc} */
  public function getOperations(EntityInterface $entity) {
    $operations = parent::getOperations($entity);
    if (isset($operations['edit'])) {
      $destination = $this->redirectDestination->getAsArray();
      $operations['edit']['query'] = $destination;
    }
    return $operations;
  }

  /** * {@inheritdoc} */
  public function render() {
    
->addListener(DeliveryNoteOrdersEvent::classfunction DDeliveryNoteOrdersEvent $event) use (&$caughtEvent): void {
                $caughtEvent = $event;
            });

        $processedTemplate = $this->deliveryNoteRenderer->render(
            [$orderId => $operation],
            $this->context,
            new DocumentRendererConfig()
        );

        static::assertInstanceOf(DeliveryNoteOrdersEvent::class$caughtEvent);
        static::assertCount(1, $caughtEvent->getOperations());
        static::assertSame($operation$caughtEvent->getOperations()[$orderId] ?? null);
        static::assertCount(1, $caughtEvent->getOrders());
        static::assertArrayHasKey($orderId$processedTemplate->getSuccess());
        $rendered = $processedTemplate->getSuccess()[$orderId];
        $order = $caughtEvent->getOrders()->get($orderId);
        static::assertNotNull($order);

        static::assertInstanceOf(RenderedDocument::class$rendered);
        static::assertCount(1, $caughtEvent->getOrders());
        static::assertStringContainsString('<html>', $rendered->getHtml());
        static::assertStringContainsString('</html>', $rendered->getHtml());

        
->addListener(CreditNoteOrdersEvent::classfunction DCreditNoteOrdersEvent $event) use (&$caughtEvent): void {
                $caughtEvent = $event;
            });

        $processedTemplate = $this->creditNoteRenderer->render(
            [$orderId => $operation],
            $this->context,
            new DocumentRendererConfig()
        );

        static::assertInstanceOf(CreditNoteOrdersEvent::class$caughtEvent);
        static::assertCount(1, $caughtEvent->getOperations());
        static::assertSame($operation$caughtEvent->getOperations()[$orderId] ?? null);
        static::assertCount(1, $caughtEvent->getOrders());
        $order = $caughtEvent->getOrders()->get($orderId);
        static::assertNotNull($order);

        if ($errorCallback) {
            $errorCallback($orderId$processedTemplate->getErrors());
        } else {
            static::assertNotEmpty($processedTemplate->getSuccess());
            static::assertArrayHasKey($orderId$processedTemplate->getSuccess());
            $rendered = $processedTemplate->getSuccess()[$orderId];
            
/** * Tests ConfigNamesMapper::hasTranslation(). */
  public function testGetOperations() {
    $expected = [
      'translate' => [
        'title' => 'Translate',
        'url' => Url::fromRoute('config_translation.item.overview.system.site_information_settings'),
      ],
    ];
    $result = $this->configNamesMapper->getOperations();
    $this->assertEquals($expected$result);
  }

}

/** * Defines a test mapper class. */
class TestConfigNamesMapper extends ConfigNamesMapper {

  /** * Gets the internal language code of this mapper, if any. * * This method is not to be confused with * ConfigMapperInterface::getLangcode(). * * @return string|null * The language code of this mapper if it is set; NULL otherwise. */
'#title' => $this->t('Weight for @title', ['@title' => $link->getTitle()]),
          '#title_display' => 'invisible',
        ];
        $form[$id]['id'] = [
          '#type' => 'hidden',
          '#value' => $link->getPluginId(),
        ];
        $form[$id]['parent'] = [
          '#type' => 'hidden',
          '#default_value' => $link->getParent(),
        ];
        $operations = $link->getOperations();
        foreach ($operations as $key => $operation) {
          if (!isset($operations[$key]['query'])) {
            // Bring the user back to the menu overview.             $operations[$key]['query'] = $this->getDestinationArray();
          }
        }
        $form[$id]['operations'] = [
          '#type' => 'operations',
          '#links' => $operations,
        ];
      }

      
->method('toUrl')
      ->willReturn($url);

    $this->redirectDestination->expects($this->atLeastOnce())
      ->method('getAsArray')
      ->willReturn(['destination' => '/foo/bar']);

    $list = new EntityListBuilder($this->entityType, $this->roleStorage);
    $list->setStringTranslation($this->translationManager);
    $list->setRedirectDestination($this->redirectDestination);

    $operations = $list->getOperations($this->role);
    $this->assertIsArray($operations);
    $this->assertArrayHasKey('edit', $operations);
    $this->assertIsArray($operations['edit']);
    $this->assertArrayHasKey('title', $operations['edit']);
    $this->assertArrayHasKey('delete', $operations);
    $this->assertIsArray($operations['delete']);
    $this->assertArrayHasKey('title', $operations['delete']);
    $this->assertArrayHasKey($operation_name$operations);
    $this->assertIsArray($operations[$operation_name]);
    $this->assertArrayHasKey('title', $operations[$operation_name]);
  }

}

  public function buildOperations(EntityInterface $entity) {
    $build = [
      '#type' => 'operations',
      '#links' => $this->getOperations($entity),
      // Allow links to use modals.       '#attached' => [
        'library' => ['core/drupal.dialog.ajax'],
      ],
    ];

    return $build;
  }

  /** * {@inheritdoc} * * Builds the entity listing as renderable array for table.html.twig. * * @todo Add a link to add a new item to the #empty text. */
$author = ['#markup' => ''];
          }

          $build[$build_id]['changes']['list'][$entity_type_id . ':' . $revision->id()] = [
            '#entity' => $revision,
            'title' => $title,
            'type' => $type,
            'changed' => ['#markup' => $changed],
            'owner' => $author,
            'operations' => [
              '#type' => 'operations',
              '#links' => $list_builder->getOperations($revision),
            ],
          ];
        }
      }

      if ($changes_count) {
        $build[$build_id]['changes']['overview']['#markup'] = implode(', ', $changes_count);
      }
    }
  }

}

  public function render(ResultRow $values) {
    $entity = $this->getEntity($values);
    // Allow for the case where there is no entity, if we are on a non-required     // relationship.     if (empty($entity)) {
      return '';
    }

    $entity = $this->getEntityTranslationByRelationship($entity$values);
    $operations = $this->entityTypeManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity);
    if ($this->options['destination']) {
      foreach ($operations as &$operation) {
        if (!isset($operation['query'])) {
          $operation['query'] = [];
        }
        $operation['query'] += $this->getDestinationArray();
      }
    }
    $build = [
      '#type' => 'operations',
      '#links' => $operations,
    ];
->addListener(StornoOrdersEvent::classfunction DStornoOrdersEvent $event) use (&$caughtEvent): void {
                $caughtEvent = $event;
            });

        $processedTemplate = $this->stornoRenderer->render(
            [$orderId => $operation],
            $this->context,
            new DocumentRendererConfig()
        );

        static::assertInstanceOf(StornoOrdersEvent::class$caughtEvent);
        static::assertCount(1, $caughtEvent->getOperations());
        static::assertSame($operation$caughtEvent->getOperations()[$orderId] ?? null);
        static::assertCount(1, $caughtEvent->getOrders());
        $order = $caughtEvent->getOrders()->get($orderId);
        static::assertNotNull($order);
        static::assertArrayHasKey($orderId$processedTemplate->getSuccess());
        $rendered = $processedTemplate->getSuccess()[$orderId];
        static::assertInstanceOf(RenderedDocument::class$rendered);
        static::assertStringContainsString('<html>', $rendered->getHtml());
        static::assertStringContainsString('</html>', $rendered->getHtml());

        $assertionCallback($rendered);
    }
Home | Imprint | This part of the site doesn't use cookies.