Hi there, It would be nice to have a method "generateSampleValue" for the class RgbItem which may allow the user to see valid random values for this field with Devel Generate.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mnico’s picture

Status: Active » Needs review
FileSize
548 bytes

The patch to add this method.

Mile23’s picture

Status: Needs review » Closed (won't fix)

Devel is a contrib module, and Examples doesn't support contrib APIs, only core APIs. The goal of field_example is to show people how to implement a field using core APIs, and this is out of scope.

Thanks, but I'm going to have to say no on this one.

mnico’s picture

I understand but this method exists in the core (https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21F...).
Maybe I was wrong in mentioning the Devel module.

Mile23’s picture

Status: Closed (won't fix) » Needs work

Oh, hah. :-) Sorry.

So this misunderstanding tells us: Needs docs explaining what this method does and what other systems use it, such as devel. Put them in the docblock after the {@inheritdoc}.

It also needs a test to tell us that the value it returns can be used in an RgbItem field. So a test which does the following: 1) Create a content type, 2) Attach the field to the content type, 3) Save a piece of content using the sample value.

Thanks.

mnico’s picture

Hi, i attached a patch with the test and the right way to implement the generateSampleValue method.

Status: Needs review » Needs work

The last submitted patch, 5: examples-field_example_generate_sample_value-2373511.patch, failed testing.

mnico’s picture

Hello, the test failed for another example module (js_example). It is necessary to work on this?

regards

Mile23’s picture

Sorry, I wanted to trigger a branch blocker.

Sit tight. :-)

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: examples-field_example_generate_sample_value-2373511.patch, failed testing.

Mile23’s picture

More testbot issues, and we're using this patch to figure it out. Sorry if you're getting a lot of notices about it.

Mile23’s picture

Re-running the test.

navneet0693’s picture

Re-rolled and changed test to KTB.

Mile23’s picture

Status: Needs review » Needs work
$ git apply examples-field_example_generate_sample_value-2373511-14.patch 
examples-field_example_generate_sample_value-2373511-14.patch:26: trailing whitespace.
  
examples-field_example_generate_sample_value-2373511-14.patch:63: trailing whitespace.
    
examples-field_example_generate_sample_value-2373511-14.patch:87: trailing whitespace.
    
examples-field_example_generate_sample_value-2373511-14.patch:95: trailing whitespace.
    
examples-field_example_generate_sample_value-2373511-14.patch:100: trailing whitespace.
    
warning: squelched 1 whitespace error
warning: 6 lines add whitespace errors.

Whitespace errors.

+++ b/field_example/tests/src/Kernel/RgbItemTest.php
@@ -0,0 +1,75 @@
+        entity_create('field_storage_config', array(
...
+        entity_create('field_config', array(
...
+        $entity = entity_create('entity_test');
...
+        $entity = entity_load('entity_test', $id);
...
+        $entity = entity_load('entity_test', $id);
...
+        $entity = entity_create('entity_test');

Deprecated functions. Wow this issue is way too old. I feel bad now.