Nothing is showed after adding computed field

Created on 18 April 2023, over 1 year ago
Updated 19 April 2023, over 1 year ago

Dear developers of the module,
Could you provide a forceful documentation how to use for D9 or D10?
I believe, at least it could be possible to place screenshots on there.

After installing the module, nothing happens... there is not a field where to put a code snippet.

Only what i see:

The hook implementation function signature should be computed_field_field_<name>_compute($entity_type_manager, $entity, $fields, $delta), and the desired value should be returned.

The variables available to your code include:

    $entity_type_manager: The entity type manager.
    $entity: The entity the field belongs to.
    $fields: The list of fields available in this entity.
    $delta: Current index of the field in case of multi-value computed fields (counting from 0).
    $value: The resulting value to be set above, or returned in your hook implementation).

How did it work for D7?

/admin/structure/types/manage/{name}/fields/field_discount

Computed Code (PHP)

if ($entity->cost > $entity->sell_price && $entity->cost > '0.00' && $entity->sell_price <> $entity->cost){
$entity_field[0]['value']= ($entity->cost - $entity->sell_price)* 100 /  $entity->cost;  
}
else{
 $entity_field[0]['value']='';}

Display Code (PHP)

if ($entity_field_item['value']  > 0 ){
$display_output = '-' .round($entity_field_item['value'], 0)." %";  
}
else{
$display_output = '';}


Or was it meant to add obligingly a custom module?


- lot of stress with Drupal 9/10
💬 Support request
Status

Fixed

Version

3.0

Component

Documentation

Created by

🇷🇺Russia allexim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @allexim
  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom joachim

    > The hook implementation function signature should be computed_field_field__compute($entity_type_manager, $entity, $fields, $delta), and the desired value should be returned.

    If you're looking at those docs, then you're using the 3.x version, not the 4.x. The 3.x version is not very actively supported.

    'hook implementation' means that you need a custom module, yes.

  • 🇷🇺Russia allexim

    Thank you for your quick reply!

    ... about v4:

    php82 /usr/local/bin/composer82 require 'drupal/computed_field:^4.0@alpha'

    /admin/structure/types/manage/video/fields

    - upon verbose error level enabled ($config['system.logging']['error_level'] = 'verbose';)

    <em>Error message</em>
        Deprecated function: Creation of dynamic property Drupal\computed_field\Form\ComputedFieldForm::$pluginManager is deprecated in Drupal\computed_field\Form\ComputedFieldForm->configureEntityViewDisplay() (line 300 of modules/contrib/computed_field/src/Form/ComputedFieldForm.php).
    
        Drupal\computed_field\Form\ComputedFieldForm->configureEntityViewDisplay('computed_php') (Line: 250)
        Drupal\computed_field\Form\ComputedFieldForm->submitForm(Array, Object)

    Drupal\computed_field\Form\ComputedFieldForm->configureEntityViewDisplay('computed_php') (Line: 250)
    Drupal\computed_field\Form\ComputedFieldForm->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 114)

    Computed value source:
    (the only one option) Reverse entity reference
    Entity reference field:
    Entity ID on Comment entities

    /admin/structure/types/manage/video/display

      All, what i see, is just a possibility to switch format:
    • rendered entity
    • entity id
    • label



    As for me, i do not have deep programming skills.
    My experience of D7 computed field doesn't allow to comprehend your module for the latest versions of Drupal - D{9,10}, it is really hard to figure out how to deal with.

  • 🇬🇧United Kingdom joachim

    > Deprecated function: Creation of dynamic property Drupal\computed_field\Form\ComputedFieldForm::$pluginManager is deprecated in

    Could you file a separate issue for that please?

    > My experience of D7 computed field doesn't allow to comprehend your module for the latest versions of Drupal - D{9,10}, it is really hard to figure out how to deal with.

    Have you read the README? That explains how to set up the module.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024