How can we create custom field and store all results using voting api ?
Voting api is used with like and dislike module, custom field value is associated with each entry and will be displayed along with like/dislike results in table.

CommentFileSizeAuthor
#2 2976876.patch508 bytesasherry

Comments

swarup.masurkar created an issue. See original summary.

asherry’s picture

Status: Active » Needs review
StatusFileSize
new508 bytes

This is related to something I was working on, you should be either able to create a custom field in hook_entity_base_field_info, or add a field in the manage fields UI.
For the latter, I had to add this patch to get it working - it seems to be missing a value in the Vote.php plugin comments.

For the former - you can currently create them programmatically with something like this:

/**
 * Implements hook_entity_base_field_info().
 */
function my_module_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'vote') {
    $definitions = [];
    $definitions['field_name'] = \Drupal\Core\Field\BaseFieldDefinition::create('type')
      ->setName('field_name')
      ->setLabel(t('Field label'))
      ->setCardinality(1);

    return $definitions;
  }
}
/**
 * Implements hook_entity_bundle_field_info().
 */
function my_module_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
  $fields = [];
  if ($entity_type->id() == 'vote' && $bundle == 'my_bundle_name') {
    $fields['field_name'] = \Drupal\Core\Field\BaseFieldDefinition::create('type')
      ->setLabel(t('Field label'))
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);
  }
}
asherry’s picture

Priority: Major » Normal

Also deescalating this, as it's not really a major issue in my opinion.

RumyanaRuseva’s picture

You may check the Votingapi Widgets module - it allows you to add Voting API fields to entities.

tr’s picture

Version: 8.x-3.x-dev » 4.0.x-dev
Issue tags: -voting api