You are here

function wsdata_field_entity_operation in Web Service Data 2.0.x

Same name and namespace in other branches
  1. 8 modules/wsdata_field/wsdata_field.module \wsdata_field_entity_operation()

Implements hook_entity_operation().

File

modules/wsdata_field/wsdata_field.module, line 17
Main module file for wsdata_field.

Code

function wsdata_field_entity_operation(EntityInterface $entity) {

  // Check if this field has the custom stroage flag set to true.
  if ('field_config' == $entity
    ->getEntityTypeId()) {
    if ($entity
      ->getFieldStorageDefinition()
      ->hasCustomStorage()) {

      // Also need to check see if there is a wsfield_config associated to it.
      $wsfield_config = \Drupal::service('entity_type.manager')
        ->getStorage('wsfield_config')
        ->load($entity
        ->get('field_name'));
      if ($wsfield_config != NULL) {
        $operations = [];
        $route_parameters = [
          'field_config' => $entity
            ->id(),
        ] + FieldUI::getOverviewRouteInfo($entity
          ->get('entity_type'), $entity
          ->get('bundle'))
          ->getRouteParameters();

        // Create the link to edit the wsfield configurations.
        $operations['edit_wsfield'] = [
          'title' => t('Web service configurations'),
          'weight' => 50,
          'url' => Url::fromRoute("entity.field_config.{$entity->getTargetEntityTypeId()}_wsfield_edit_form", $route_parameters),
          'attributes' => [
            'title' => t('Edit web service configurations'),
            'class' => [
              'dropbutton-action',
              'web-service-config',
            ],
          ],
        ];
        return $operations;
      }
    }
  }
}