This forum is for module development and code related questions, not general module support. For general support, use the Post installation forum.

How to reference image in Drupal post api

I am following Drupal guidelines to upload, and reference image in POST api to set image in a content. 

Although I can upload a image, I can not able to set the image properly. 

"field_image_article": [
        {
            "fid": 69378,
            "title": "This image is awesome"
        }
    ] 

or 

"field_image_article": [{ "fid": 69378 }] 

Not working. 

My POST api PHP code 

Views better exposed filter to filter csv data

I have a content type field which takes data in csv format , I have created a view , Now I want to create a exposed filter for that csv field to check if that particular data exists or not in the csv ( I have a csv file which contains Vin numbers of cars ) and now I want a exposed filter where I enter a Vin no and it checks if it exists or not )

How to avoid locking code implementing a custom field to specific names

I have created a custom module that creates a custom text field. The general idea is that site builders who install this module shall be able to use this custom field when creating a custom content type using the Drupal UI.

I have most of this working for me now, but it is not ready for others, for the following reasons:

Add a Form inside the table header.

How Can I add a Drupal 8 form inside the table header?

Validate form with multivalue field

I have a multivalue text plain field in a custom content type.

I have custom validation for this field that looks like this:

public function validate($element, FormStateInterface $form_state) {
  $value = $element['#value'];
  $validvalue = $this->isValid($value);
  if ($validvalue) {
    $form_state->setValue('field_myfield', [['value' => $validvalue]]);
  }
  else {
    $form_state->setError($element, $this->t('Not valid.');
  }
}

As long as the field only contains a single value, this works great.

Is there an alternative way to do this with dependecy injection?

I have a custom submit handler for a field in class that extends WidgetBase. I need to alter the value for a custom field.

I currently do it with this code line:

$form_state->setValue('field_myfield', [['value' => $value]]);

It works fine.

However, I understand that dependency injection should be used in OO code if possible.

Pages

Subscribe with RSS Subscribe to RSS - Module development and code questions