8 – Custom normalizer throws error once enabled

I wrote a custom normalizer last year to alter link output (using https://www.mediacurrent.com/blog/using-normalizers-alter-rest-json-structure-drupal-8/ as reference) for use with JSON:API output, which worked like a charm. However, at the moment I get a big error (see below) when I’ve enabled the module.

The error:

TypeError: Adaptor Drupaljsonapi_extrasPluginResourceFieldEnhancerBase returned invalid output data: () in Drupaljsonapi_extrasPluginResourceFieldEnhancerBase->undoTransform() (line 66 of /vendor/e0ipso/shaper/src/DataAdaptor/DataAdaptorTransformerTrait.php).
Drupaljsonapi_extrasPluginResourceFieldEnhancerBase->undoTransform(Array, Object) (Line: 65)
Drupaljsonapi_extrasNormalizerResourceIdentifierNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
SymfonyComponentSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 62)
DrupaljsonapiSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 26)
DrupaljsonapiNormalizerDataNormalizer->DrupaljsonapiNormalizer{closure}(Object)
array_map(Object, Array) (Line: 27)
DrupaljsonapiNormalizerDataNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
SymfonyComponentSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 62)
DrupaljsonapiSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 26)
DrupaljsonapiNormalizerRelationshipNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
SymfonyComponentSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 62)
DrupaljsonapiSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 187)
DrupaljsonapiNormalizerResourceObjectNormalizer->serializeField(Object, Array, 'api_json') (Line: 121)
DrupaljsonapiNormalizerResourceObjectNormalizer->getNormalization(Array, Object, 'api_json', Array) (Line: 73)
DrupaljsonapiNormalizerResourceObjectNormalizer->normalize(Object, 'api_json', Array) (Line: 38)
Drupaljsonapi_extrasNormalizerJsonApiNormalizerDecoratorBase->normalize(Object, 'api_json', Array) (Line: 24)
Drupaljsonapi_extrasNormalizerResourceObjectNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
SymfonyComponentSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 62)
DrupaljsonapiSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 26)
DrupaljsonapiNormalizerDataNormalizer->DrupaljsonapiNormalizer{closure}(Object)
array_map(Object, Array) (Line: 27)
DrupaljsonapiNormalizerDataNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
SymfonyComponentSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 62)
DrupaljsonapiSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 193)
DrupaljsonapiNormalizerJsonApiDocumentTopLevelNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
SymfonyComponentSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 62)
DrupaljsonapiSerializerSerializer->normalize(Object, 'api_json', Array) (Line: 120)
DrupaljsonapiEventSubscriberResourceResponseSubscriber->renderResponseBody(Object, Object, Object, 'api_json') (Line: 85)
DrupaljsonapiEventSubscriberResourceResponseSubscriber->onResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 111)
DrupalComponentEventDispatcherContainerAwareEventDispatcher->dispatch('kernel.response', Object) (Line: 191)
SymfonyComponentHttpKernelHttpKernel->filterResponse(Object, Object, 1) (Line: 173)
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: 191)
Drupalpage_cacheStackMiddlewarePageCache->fetch(Object, 1, 1) (Line: 128)
Drupalpage_cacheStackMiddlewarePageCache->lookup(Object, 1, 1) (Line: 82)
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)

My services.yml

services:
  custom_normalizer.typed_data:
    class: Drupalcustom_normalizerNormalizerLinkNormalizer
    tags:
      - { name: normalizer, priority: 10 }

The LinkNormalizer file:

<?php

namespace Drupalcustom_normalizerNormalizer;

use DrupalCoreUrl;
use DrupallinkPluginFieldFieldTypeLinkItem;
use DrupalserializationNormalizerNormalizerBase;

/**
 * Converts typed data objects to arrays.
 */
class LinkNormalizer extends NormalizerBase
{
    /**
     * The interface or class that this Normalizer supports.
     *
     * @var string
     */
    protected $supportedInterfaceOrClass = 'DrupalCoreTypedDataTypedDataInterface';

    /**
     * {@inheritdoc}
     */
    public function normalize($object, $format = null, array $context = array())
    {
        $value = $object->getValue();
        $parent = $object->getParent();
        if ($parent instanceof LinkItem) {
            $internalLink = $parent->get('uri')->getValue();
            $link = Url::fromUri($internalLink, array('absolute' => false))->toString();
            $object->getParent()->get('options')->setValue(('url' => $link));
        }
        return $value;
    }
}

If anyone has an idea what I’m doing wrong (or what has changed), that would be great. I haven’t found anything useful yet.

Stephan

data transfer – SQLiteDatabase.openDatabase() throws (code 14 SQLITE_CANTOPEN): Could not open database for copied db file?

I have a SQLite database file, which was already populated somewhere else;

test.db

I would like to open this database file in my app: e.g. com.example.dbapp on READYONLY mode for instance.

  1. Created a folder databases in /data/data/com.example.dbapp/
  2. Copied that test.db into this new created folder /data/data/com.example.dbapp/databases/test.db

Then I attempt to open in old plain SQLiteOpenHelper like:

class MyDatabaseHelper(private val myContext: Context) : SQLiteOpenHelper(myContext, DB_NAME, null, 10) {

    companion object {
        private const val DB_NAME = "test.db"
    }

    val DB_PATH = "/data/data/com.example.getchannels/databases"

    lateinit var myDataBase: SQLiteDatabase

    fun openDataBase() {
        val myPath = DB_PATH + DB_NAME
        try {
            myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY)
        } catch (e: SQLException) {
            Log.e("XXX", "DB open FAIL: $e.getlocalizedMessage()")
        }
    }

    @Synchronized
    override fun close() {
        myDataBase?.close()
        super.close()
    }

    override fun onCreate(db: SQLiteDatabase) {
    }

    override fun onUpgrade(db: SQLiteDatabase, oldV: Int, newV: Int) {
    }

    fun getAll(): Cursor {
        return myDataBase?.rawQuery("SELECT * FROM ${DB_NAME.toString()}", null)!!
    }
    
}

In my MainActivity:

val myDB = MyDatabaseHelper(this@MainActivity)
myDB.openDataBase()

Nevertheless, the catch clause in openDataBase() throws an SQLException :

unknown error (code 14 SQLITE_CANTOPEN): Could not open database

?!

sqlite – SQLiteDatabase.openDatabase() throws code 14 SQLITE_CANTOPEN for com.android.provider.tv/databases/tv.db?

I would like to open and read an already existing SQLite database, in particular following SQLite database:

/data/data/com.android.providers.tv/databases/tv.db

In this case I would like to open a database already created by something (system) else..

I tried this with old plain SQLiteOpenHelper:

class TvDatabaseHelper(private val myContext: Context) : SQLiteOpenHelper(myContext, DB_NAME, null, 10) {

    companion object {
        private const val DB_NAME = "tv.db"
        private val DB_PATH = "/data/data/com.android.providers.tv/databases/"
    }

    lateinit var myDataBase: SQLiteDatabase

    fun openDataBase() {
        val myPath = DB_PATH + DB_NAME
        try {
            myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY)
        } catch (e: SQLException) {
            Log.e("XXX", "DB open FAIL: $e.getlocalizedMessage()")
        }
    }

    @Synchronized
    override fun close() {
        myDataBase?.close()
        super.close()
    }

    override fun onCreate(db: SQLiteDatabase) {
    }

    override fun onUpgrade(db: SQLiteDatabase, oldV: Int, newV: Int) {
    }

    fun getAll(): Cursor {
        return myDataBase?.rawQuery("SELECT * FROM $DB_NAME}", null)!!
    }
    
}

In my MainActivity I check

Log.d("XXX","UIDs: ${applicationInfo.uid}:$SYSTEM_UID")

and both say 1000:1000 so this app was pushed to /system/apps/test/ and runs as su.

Nevertheless, the catch clause in openDataBase() throws an SQLException :

unknown error (code 14 SQLITE_CANTOPEN): Could not open database

?!

error – Require.js loads the function (it exists in bundle.js), but console throws “not defined”

Having an issue with one of the plugins recently installed.

My DEV server and local DEV servers both are working normal, not throwing errors, but PRODUCTION server throws “Uncaught ReferenceError: tmlsOwlCarousel is not defined”.

Both PRODUCTION and DEV are running in the PRODUCTION mode. Local DEV runs in DEVELOPMENT mode.

Here is the code that executes it:

require((
'jquery',
 // tried DOM READY, didn't work.
'domReady!',
"Ves_All/lib/owl.carousel/owl.carousel.min",
'Ves_Testimonial/js/testimonial-carousel',
), function ($) {
    $( document ).ready(function() {            
    // tried to see if it ever loads the function - it doesnt
    //setInterval(function(){ console.log(typeof tmlsOwlCarousel); }, 1000);

    tmlsOwlCarousel("#testimonial-carousel-10199329431611963779", ".owl-carousel");
        $('#testimonials10199329431611963779 .tmls-readmorelink').click(function() {
            var parent = $(this).parents('.tmls-testimonial');
            $(parent).find('.tmls-excerpttext').hide();
            $(parent).find('.tmls-fulltext').fadeIn('slow');
        });
        $('#testimonials10199329431611963779 .tmls-item').mouseleave(function() {
            $(this).find('.tmls-excerpttext').fadeIn('slow');
            $(this).find('.tmls-fulltext').hide();
        });
    });
});

I have looked inside of the bundle.js file and that function exists and is being loaded.

I also tried onLoad / onReady / domReady and setInterval to see if that function ever loads, but it doesn’t.

bundle.js file is about 2MB, so I’m not sure if it’s the file size or what is happening here.

Why would it never load if it does exist in the bundle file?

UPDATE:

The function that fails exists in: Ves_Testimonial/js/testimonial-carousel.js file. The file exists in the /static folder and is being loaded into the bundle.js

UPDATE:

requirejs-config.min.js also contains Ves_Testimonial/js/testimonial-carousel.js

(function () {
    var config = {
      map: {
        '*': {
          testimonial_fancybox: 'Ves_Testimonial/js/jquery.fancybox.pack',
          rating: 'Ves_Testimonial/js/rating',
          testimonial_rating: 'Ves_Testimonial/js/testimonial_rating',
          testimonial_carousel: 'Ves_Testimonial/js/testimonial-carousel',
          testimonialtowlcarousel: 'Ves_Testimonial/js/owl.carousel.min'
        }
      },
      shim: {
        'testimonial_carousel': {
          deps: (
            'jquery',
            'Ves_All/lib/owl.carousel/owl.carousel.min'
          )
        },
        'Ves_Testimonial/js/carouFredSel': {
          deps: (
            'jquery'
          )
        },
        'Ves_Testimonial/js/testimonial-carousel': {
          deps: (
            'jquery',
            'Ves_All/lib/owl.carousel/owl.carousel.min'
          )
        },
        'testimonialtowlcarousel': {
          deps: (
            'jquery'
          )
        }
      }
    };
    require.config(config);
  }) ();

url rewriting – Categories of Custom Post throws gives 404

I’ve created a custom post type for a website. This is the code:

// Register Custom Expert Advice
function expert_advice_post_type() {
    $labels = array(
        'name'                => __( 'Expert Advice' ),
        'singular_name'       => __( 'Expert Advice')
    );
    $args = array(
        'label'               => __( 'expert-advice'),
        'description'         => __( 'Expert Advice'),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
        'public'              => true,
        'hierarchical'        => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'has_archive'         => true,
        // "has_archive"         => 'expert-advice',
        'can_export'          => true,
        'exclude_from_search' => false,
        'yarpp_support'       => true,
        'taxonomies'          => array('post_tag'),
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
);
    register_post_type( 'expert-advice', $args );
    
    add_image_size( 'like_thumbnail', 262, 175,true );
    add_image_size( 'arhive_thumbnail', 350, 300,true );
}
add_action( 'init', 'expert_advice_post_type', 0 );

add_action( 'init', 'expert_advice_custom_taxonomy', 0 );
function expert_advice_custom_taxonomy() {
 
  $labels = array(
    'name' => _x( 'Categories', 'taxonomy general name' ),
    'singular_name' => _x( 'Category', 'taxonomy singular name' ),
    'menu_name' => __( 'Categories' ),
  );    
 
  register_taxonomy('expert-advice',array('expert-advice'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite'      => true,
  ));
  }

It seems to work fine for posts but it throws 404 for archive pages.

I am looking for url structure like this :

Event post type archive URL:
/expert-advice

Event post type URLs:
/expert-advice/example-event-post-name/

Event category URLs:
/expert-advice/category/

8 – Converting existing single site to multisite throws error

I’m trying to convert an existing 2 Single site to a Multisite.

Steps:

  • Created 2 folders [subsite1, subsite2] inside the sites folder.
  • Moved files from a single site to sites/subsite1/files.
  • Added alias [subsite1.com, subsite2.com] in sites.php for subsites.
  • Added settings.php and modified DB details.

When I hit the alias URL subsite1.com, it throws “The website encountered an unexpected error. Please try again later.” when I checked in drush watchdog it shows enter image description here

What are the things that need to be changed in DB. Any suggestions?

magento2 – Composer Install throws error downloading Magento Package in Magento 2.4.1

Trying to run composer install in a Magento 2.4.1 project is netting the following error:

The "https://repo.magento.com/archives/magento/module-page-builder/magento-module-page-builder-2.1.0.0.zip" file could not be downloaded (HTTP/1.1 404 Not Found)

All magento modules previous to this work, which means the Keys works. I have even created a different key to try and still same issue. What can I do?

dnd 5e – Does the Mind Sliver cantrip’s effect on saving throws stack with the Bane spell?

The cantrip mind sliver from Tasha’s Cauldron of Everything (p. 108) has a secondary effect that subtracts 1d4 from the target’s next saving throw:

(…) subtract 1d4 from the next saving throw it makes before the end of your next turn.

The spell bane from the Player’s Handbook (p. 216) has a similar effect:

(…) the target must roll a d4 and subtract the number rolled from the attack roll or saving throw.

Does the saving throw penalty from mind sliver stack with the effect of bane, causing the target to subtract 2d4 from their next saving throw?

struct – Swift UI, removing item from array, while looping in it throws Fatal Error: Index out of range

import SwiftUI

struct Item{
    var name = "My Item"
    var price = "10$"
}



struct ContentView: View {
    @State var items:(Item) = (Item(), Item())

    var body: some View {
        VStack{
            ForEach(self.items.indices, id: .self){index in
                HStack{
                    TextField("Item Name", text: self.$items(index).name)
                    TextField("Item Price", text: self.$items(index).price)
                }
            }
            
            HStack{
                Button(action: {self.addItem()}, label: {Text("Add Item")})
                Button(action: {self.removeItem()}, label: {Text("Remove Item")})
                
                Spacer()
            }
        }
            .padding()
    }
    
    func addItem(){
        self.items.append(Item())
    }
    
    func removeItem(){
        self.items.removeLast()
    }
}

In above example I created views in a loop using ForEach to be able to change values in struct and dynamically add and remove items. Adding items works, but removing item throws Fatal Error:

Fatal error: Index out of range: 
file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1103.8.25.8/swift/stdlib/public/core/ContiguousArrayBuffer.swift, line 444
2020-12-17 15:03:36.046851+0300 testapp(3205:76975)
Fatal error: Index out of range: 
file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1103.8.25.8/swift/stdlib/public/core/ContiguousArrayBuffer.swift, line 444

Error message in editor isn’t very helpful:

AppDelegate.swift

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {    = | Thread 1: Fatal error: Index out of range

When I comment out TextFields removing items works fine. I suspect, that self.$items(index).name tries to get it’s index, but it was removed.

Any help is appreciated.

dnd 5e – What magic items from the DMG give a +1 to saving throws?

My DM gave a few magic items to the party after a particularly rough encounter with a dragon a month or so ago. One player was absent, so we only had 3, and another player’s character died. The result of this is that my greedy gnome criminal and the guileless half-orc fighter were the only 2 characters alive. Of course, I took all the magic items.

My DM can’t remember what one of the items was, and neither can I. All we know is it gave a +1 bonus to saving throws, and was in the DMG.

What magic items from the DMG give +1 bonus to all saving throws?