theming – (Rookie Question) Set background picture only within the text field, not entire page on Drupal 7

How should i make the background image appear within the text field (in context type: basic page) but not the entire web page?

I am using Background Image Formatter, running on Drupal 7 with Bootstrap 3.
Module url: (

I would like to appear within the text field

This is my current config
I am extremely new to web development and Drupal. Apologies if such question offends you. Any answer is appreciated!

How to remove text from the body field in views and leave only <img> tag?

Good evening, i have articles that contain texts and images, i would like to know if there is any way in views to strip or remove the text from body field leaving just the img tag, i don´t want to use image field module.

8 – How to create Media entity and attach to user field

I’m trying to import user profile pictures from Drupal 7 to Drupal 8. So far I’ve managed to upload the picture from the url and save it to the file system, create Media entity and use the user id as author. However, the picture doesn’t show to the user profile (Manage Form Display), neither to the Edit Media Content Type page.

Here is the code I have so far:

$values = array(
      'name' => $user("name"),
      'pass' => (
         'value' => $user("pass"),
         'pre_hashed' => TRUE,
      'status' => $user("status"),
      'mail' => $user("mail"),
      'field_first_name' => $user("field_first_name"),
      'field_last_name' => $user("field_last_name"),

$userStorage = Drupal::entityTypeManager()->getStorage('user');
$userEntity = $userStorage->create($values);

    $replaced = str_replace("\", "", $user("picture"));
    $imageData = file_get_contents($replaced);
    $fileName = basename($replaced);
    $file = file_save_data(
        "public://". $fileName, 
    $media = Media::create((
        'bundle' => 'image',
        'uid' => $userEntity->id(),
        'langcode' => Drupal::languageManager()->getDefaultLanguage()->getId(),
        'field_media_file' => (
             'target_id' => $file->id(),
             'alt' => $file->getFilename(),
        'thumbnail' => (
             'target_id' => $file->id(),
             'alt' => $file->getFilename(),

Is the something missing in the code?

8 – Ajax HtmlCommand not working on form field in a field group

I’ve added a custom ajax callback to a field that I’m trying to update the value of. The Field I’m updating is inside a field group and instead of updating the field it just empties the html.

The form item with the ajax callback

$form('sku') = (
  '#type' => 'entity_autocomplete',
  '#title' => $this->t('SKU'),
  '#target_type' => 'node',
  '#selection_handler' => 'views',
  '#selection_settings' => (
    'view' => (
      'view_name' => 'parts_reference',
      'display_name' => 'entity_reference_1',
      'arguments' => ()
    'match_operator' => 'CONTAINS'
  '#weight' => '0',
  '#size' => '200',
  '#ajax' => (
    'callback' => '::oeRefAjaxCallback',
    // don't forget :: when calling a class method.
    //'callback' => ($this, 'myAjaxCallback'), //alternative notation
    'disable-refocus' => FALSE,
    // Or TRUE to prevent re-focusing on the triggering element.
    'event' => 'change',
    // This element is updated with this AJAX callback.
    'progress' => (
      'type' => 'throbber',
      'message' => $this->t('Verifying entry...'),

The form item that is to be updated

$form('item_specifics_type') = (
  '#title' => 'Type',
  '#type' => 'textfield',
  '#value' => '',
  '#size' => '60',
  '#group' => 'fieldset_item_specifics',
  '#prefix' => '<div id="item-specific-type-wrapper">',
  '#suffix' => '</div>'

$response->addCommand(new HtmlCommand('#item-specific-type-wrapper', $form('item_specifics_type')));

If I remove the group key from the field array so that the field is not in the fieldset then the ajax command replaces the field with the correct html as expected.

8 – Page title and body field of specific page

If you must do this in twig only, you can use the drupal_field() function provided by the Twig Tweak module.

For example, to print the title of node 2:

{{ drupal_field('title', 'node', 2) }}

Or to print the body field for node 2 using the field’s configuration from the teaser view mode:

{{ drupal_field('body', 'node', 2, 'teaser') }}

Or to print an image field with custom formatter settings:

{{ drupal_field('field_image', 'node', 2, {type: 'image_url', settings: {image_style: 'large'}}) }}

I’d probably aim to create a custom view mode here and then print the whole view mode as one chunk with the drupal_entity() function. For example:

{{ drupal_entity('node', 2, 'my_custom_view_mode') }}

8 – Creating a custom field programmatically with a link to the entity gives me an error

When creating a custom field with a reference to an entity, the following error appears. Here is the link of the article from where I took the example field

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method DrupalCoreFieldFieldItemList::referencedEntities() in DrupalCoreFieldPluginFieldFieldWidgetEntityReferenceAutocompleteWidget->formElement() (line 98 of core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php).
DrupalCoreFieldPluginFieldFieldWidgetEntityReferenceAutocompleteWidget->formElement(Object, 0, Array, Array, Object) (Line: 29)
Drupalorders_for_crmPluginFieldFieldWidgetOrderProductsFieldWidget->formElement(Object, 0, Array, Array, Object) (Line: 344)
DrupalCoreFieldWidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 211)
DrupalCoreFieldWidgetBase->formMultipleElements(Object, Array, Object) (Line: 113)
DrupalCoreFieldWidgetBase->form(Object, Array, Object) (Line: 287)
DrupalCoreFieldFieldItemList->defaultValuesForm(Array, Object) (Line: 127)
Drupalfield_uiFormFieldConfigEditForm->form(Array, Object) (Line: 149)
DrupalCoreEntityEntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 532)
DrupalCoreFormFormBuilder->retrieveForm(‘field_config_edit_form’, Object) (Line: 278)
DrupalCoreFormFormBuilder->buildForm(Object, Object) (Line: 91)
DrupalCoreControllerFormController->getContentResult(Object, Object) (Line: 39)
Drupallayout_builderControllerLayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() (Line: 573)
DrupalCoreRenderRenderer->executeInRenderContext(Object, Object) (Line: 124)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() (Line: 151)
SymfonyComponentHttpKernelHttpKernel->handleRaw(Object, 1) (Line: 68)
SymfonyComponentHttpKernelHttpKernel->handle(Object, 1, 1) (Line: 57)
DrupalCoreStackMiddlewareSession->handle(Object, 1, 1) (Line: 47)
DrupalCoreStackMiddlewareKernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupalpage_cacheStackMiddlewarePageCache->pass(Object, 1, 1) (Line: 85)
Drupalpage_cacheStackMiddlewarePageCache->handle(Object, 1, 1) (Line: 47)
DrupalCoreStackMiddlewareReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
DrupalCoreStackMiddlewareNegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
StackStackedHttpKernel->handle(Object, 1, 1) (Line: 708)
DrupalCoreDrupalKernel->handle(Object) (Line: 19)

How to plot a vector field with arrow length and background color for strength and direction

I want to visualize a 2D vector field, e.g.,

Table(Exp(-(x^2 + y^2)/4) {y, -x}, {x, -3, 3, 0.2}, {y, -3, 3, 0.2})

in a way where the arrow length denotes the vector length and the background color indicates the local vector orientation. Just something like the following. How can one achieve this in Mathematica?enter image description here

categories – How to print total of some posts custom field value

I was trying to print total of some posts custom field value. In the below code there has an error I am unable to figure out.

I have a couple of posts that have custom field named as Number and their values are (For Example) 25, 70, 15, etc.

Now I want to print total of Custom Field Values for the recent 10 posts that are common from Tag (ID = 5) and Category (ID = 6).

My shortcode is (Totalpost category=”6″ tag=”5″ posts_per_page=”10″)

Anybody can fix this code? I will be thankful to you.

function get_total_post($query_args) {
     'category__and' => $att('category'),
        'tag__in' => $att('tag'),
        'post_status' => 'publish',
        'posts_per_page' => $att('posts_per_page'));  
      $total = 0;
    $posts = get_posts($query_args);
    foreach ($posts as $post) {
        $total += get_field('Number', $post->ID);
    return $total;
 function show_total_post() {
    print get_total_post(array());
add_shortcode('Totalpost', 'show_total_post');

magento2 – How to modify data of Custom Field before rendering to backend form?

I have created a simple crud module that renders form with a few basic fields and saves data into database. Module is working fine and saving data correctly in the database.

Issue is before rendering form value I want to add a prefix to URL, something like this.

public function getInstagramLink()
    return 'https:'.$this->getData('instagram_link');

I have added this method within Model but that doesn’t seem to be working

namespace VendorModuleModel;

class Instalocator extends MagentoFrameworkModelAbstractModel
    protected function _construct()
        $this->_init(VendorModuleModelResourceModelInstalocator ::class);

    public function getInstagramLink()
        return 'https:'.$this->getData('instagram_link');

This doesn’t seem to be working. How to do this correctly to set/get value before/after saving into database?

8 – Adding the category for a custom entity reference field add other fields to the same category

I have a custom entity reference field working well, but once I added the category to it the other entity reference fields appeared in the same category.

enter image description here

Here is my code:

 * Plugin implementation of the 'region_token' field type.
 * @FieldType(
 *   id = "region_token",
 *   label = @Translation("Region Token"),
 *   description = @Translation("Region custom token."),
 *   category = @Translation("Tokens"),
 *   default_widget = "region_select_widget",
 *   default_formatter = "region_formatter",
 * )
class RegionToken extends EntityReferenceItem {

Any idea about how to fix this?