Module Hook to add extra field in drupal 8 content types - module

I want to add an extra field in Drupal 8 content types with a custom module and I am not getting any hook to do.
Below is the hook I am using but that is not helping me with the result I want :
function nodeclass_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
// Add a property only to nodes of the 'article' bundle.
if ($entity_type->id() == 'node' && $bundle == 'article') {
$fields = array();
$fields['mymodule_text_more'] = BaseFieldDefinition::create('string')
->setLabel(t('More text'))
->setComputed(TRUE)
->setClass('\Drupal\mymodule\EntityComputedMoreText');
return $fields;
}
}

Inside your module folder, create the below folders
modules/my_module/config/install/
Then create the below files inside your module folder.
my_module/config/install/field.field.node.article.field_text_more.yml
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_text_more
- node.type.article
id: node.article.field_text_more
field_name: field_text_more
entity_type: node
bundle: article
label: 'More text'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
my_module/config/install/field.storage.node.field_text_more.yml
langcode: en
status: true
dependencies:
module:
- node
id: node.field_text_more
field_name: field_text_more
entity_type: node
type: string
settings:
max_length: 255
is_ascii: false
case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Then re-install your module, it will add the new field "More text" into "Article" content type.
Note: Change file name and update the line "bundle: article" in field.field.node.article.field_text_more.yml if you wish to add fields to any other content type.

Related

trying to get an objects key which is a 'letters + counter number' variable but it won't work

I know tis might be a silly problem but I'm not sure how to frame this line of code to do what I need. I'm using Vue CLI and I have a some objects within an array in my data. one of those objects have several image links with key that goes -> img1 : ./link, img2: ./link2. In my function i need to change the target elements source to the next image i.e from img1 to img2 where I have a counter that stores the number that i want img to change to. however the results only show NaN.
here is my some HTML:
<img #click="storyboard" v-else :src="slide.img1" />
<div class="counter hide">
<p>{{ counter }} / 5</p>
</div>
here is some JS
data() {
return {
slides: [
{ title: 'Landing Page', img1: require("../assets/wadah/proposal.mp4"), info: "Wadah Archive is an alternative museum where everyday artefacts are given meaning through crowdsourced nostalgia. The online archive stresses on the idea that the stories and conversations about the artefact by people visiting the archive should be a part of the artefact itself. It is a reflection on traditional methods of preserving and displaying objects through proposing an alternative navigation system by translating physical artefacts into a digital space.", makeSmall: false
}, {
title: "Interacting with 3D objects", img1: require("../assets/wadah/pinStill.jpg"), info: "dummydata", makeSmall: false
}, {
title: "Designing Pins and Signage", img1: require("../assets/wadah/pins.png"), info: "dummydata", makeSmall: true
},{
title: "Home and Index Navigation", img1: require("../assets/wadah/home1.jpg"), img2: require("../assets/wadah/home3.jpg"), img3: require("../assets/wadah/home2.jpg"), img4: require("../assets/wadah/index.jpg"), img5: require("../assets/wadah/index2.jpg"), info: "dummydata", makeSmall: false
},{
title: "User Flow", img1: require("../assets/wadah/wireflow.png"), info: "dummydata", makeSmall: false
},
],
visibleSlide: 0,
counter: 1
}
}
methods: {
storyboard(event) {
if (this.visibleSlide === 3) {
let ele = event.target
this.counter++
ele.src = this.slides[3].img + this.counter
// console.log(this.slides[3].img + 2)
// console.log(ele.src, this.counter)
}
}
}
const obj = {
title: "Home and Index Navigation",
img1: "../assets/wadah/home1.jpg",
img2: "../assets/wadah/home3.jpg",
img3: "../assets/wadah/home2.jpg",
img4: "../assets/wadah/index.jpg",
}
let counter = 2
console.log("Incorrect:", obj.img + counter) // obj.img does not exists = undefined
console.log("Correct:", obj["img"+counter])

How can I retrieve nested values in Keystone 5 for my list

I'm adding a list called 'tourlocation' to my Keystone 5 project. In my mongo database my tourlocations collection has an object called 'coordinates', with two values: 'lat' and 'long'. Example:
"coordinates" : {
"lat" : 53.343761,
"long" : -6.24953
},
In the previous version of keystone, I could define my tourlocation list coordinates object like this:
coordinates: {
lat: {
type: Number,
noedit: true
},
long: {
type: Number,
noedit: true
}
Now unfortunately, when I try to define the list this way it gives the error: The 'tourlocation.coordinates' field doesn't specify a valid type. (tourlocation.coordinates.type is undefined)'
Is there any way to represent objects in keystone 5?
#Alex Hughes I believe your error says "type" which you may need to add it like this
keystone.createList('User', {
fields: {
name: { type: Text }, // Look at the type "Text" even in the MongoDB you can choose the type but it will be better to choose it here from the beginning.
email: { type: Text },
},
});
Note that noedit: true is not supported in version 5 of KeystoneJS.
For more info look at this page https://www.keystonejs.com/blog/field-types#core-field-types

extjs 4 how to declare a global variable from a store

We have an extJs4 - spring MVC application.
I would like to declare a variable with user information (name, firstname, role). With role we can set field in read only or to hidde some part of the application.
In my app.js:
Ext.application({
name: 'appname',
appFolder: 'js/app',
enableQuickTips:true,
controllers: [
'MainController',....
],
autoCreateViewport: true,
globals:
var1 : 5 //it works for simple variable
});
I would like to create store variable with this
var appglobalstore = Ext.getStore('MyStore');
This is not possible :
globals:
appglobalstore : Ext.getStore('MyStore');
And to get value in extjs like that (I guess)
var role= appname.app.globals.role
Is it possible ? Or if it's not possible, whereever I need the role do I have to declare ? like that
var role = Ext.getStore('myStore').getAt(0).raw.role;
The name given to your app is the name of the global variable that ExtJS provides to you.
So, you can do that:
appname.role = role = Ext.getStore('myStore').getAt(0).raw.role;
Then you can access to your role by:
var x = appname.role;
And you can assign your value to "appname.role" in the launch attribute of your application:
Ext.application({
name: 'appname',
appFolder: '/extjs-app/app',
controllers: [
'MainController', ..
],
requires: [
'appname.utils.Logger', ...
],
autoCreateViewport: true,
launch: function() {
appname.role = role = Ext.getStore('myStore').getAt(0).raw.role;
}
});

Can't get the elements of the sencha store

So I have a store
Ext.define('APN.store.BackupShow', {
extend: 'Ext.data.Store',
requires: [
'APN.model.ScheduledShow'
],
config: {
model: 'APN.model.ScheduledShow',
proxy: {
type: 'ajax',
url: '',
reader: {
type: 'xml',
record: 'item',
rootProperty: 'xml'
}
}
},
getShow: function () {
if (this.getData().length greater 1) # by some reason stackoverflow didn't allow me to put greater sign in here;
return null;
// Copy field data across as wrong field is popped.
this.getAt(0).set("listimage", this.getAt(0).get("onairimage"));
this.getAt(0).set("isbackup", "true");
return this.getAt(0);
}
});
And when I'm trying to call the first element of the store I get undefined, however the element exists in the store:
(0) console.log(backupShowStore);
(1) console.log(backupShowStore.data);
(2) console.log(backupShowStore.getData().all);
(3) console.log(backupShowStore.getData().all.length);
(4) console.log(backupShowStore.getData().all.getAt(0));
I got back:
(1)
Class
_data: Class
_model: function () {
_modelDefaults: objectClass
_proxy: Class
_remoteFilter: false
_remoteSort: false
_storeId: "backupShow"
_totalCount: null
config: objectClass
data: Class
_autoFilter: true
_autoSort: true
_filterRoot: "data"
_sortRoot: "data"
all: Array[1]
0: Class
_data: Object
data: Object
bufferingProgress: null
contentlink: null
description: null
facebooklink: "http://www.facebook.com/mixmelbourne"
id: "ext-record-45"
isbackup: null
listimage: null
onairimage: "http://arntrnassets.mediaspanonline.com/radio/mxm/53808/on-air-default_v3.png"
showbody: "Melbourne's widest variety from 2K to today, Mix101.1 with Chrissie & Jane waking up Melbourne weekdays from 6am."
showbyline: "The widest variety from 2K to today"
showcontentxml: null
showemail: null
showname: "Mix 101.1"
showschedule: null
smallimage: null
title: null
twittername: "mixmelbourne"
__proto__: Object
id: "ext-record-45"
internalId: "ext-record-45"
modified: Object
phantom: true
raw: item
stores: Array[1]
__proto__: TemplateClass
length: 1
__proto__: Array[0]
(2)
_autoFilter: true
_autoSort: true
_filterRoot: "data"
_sortRoot: "data"
all: Array[1]
config: objectClass
dirtyIndices: true
getKey: function (record) {
indices: Object
initConfig: function (){}
initialConfig: Object
items: Array[1]
keys: Array[1]
length: 1
map: Object
__proto__: TemplateClass
(3)
Array[1]
0: Class
length: 1
__proto__: Array[0]
(4)
0
(5)
Uncaught TypeError: Object [object Array] has no method 'getAt'
Which is understandable for (5) as array doesn't have method getAt, however the store doesn't have any items and that is indicated by (4) where the array of getData elements equals to 0...
Am very confused at this point of time with Sencha Touch Framework and how to get the first element of an array of elements
Why not just use the Ext.data.Store.first() method.
I have found I am typically a happier developer when I use the methods provided by the api. On the rare occasion that I need something not provided I will navigate the Sencha Objects myself but I really try not to.
Let me know if and why that solution might not work and I'll try to find something else for you.

Problems converting a INI based configuration into YAML

Greetings to all.
I am working on a project that uses Zend_Config to create forms. I am working on broadening my knowledge base and have hit a snag.
I have a form config file in ini format that works fine. I would like to convert that form configuration into a YAML based file. I attempted to write the conversion myself, and though I accounted for everything. As this is my first journey into yaml, I need help to see what is wrong.
The ini file that works is here:
[production]
;General From Meta Data
logon.form.action = "/customers/plogin"
logon.form.method="post"
logon.form.id="loginform"
;Form Element Prefix Data
logon.form.elementPrefixPath.decorator.prefix = "Elite_Decorator_"
logon.form.elementPrefixPath.decorator.path = "Elite/Decorator/"
logon.form.elementPrefixPath.decorator.type = "decorator"
logon.form.elementPrefixPath.validate.prefix = "Elite_Validate_"
logon.form.elementPrefixPath.validate.path = "Elite/Validate/"
logon.form.elementPrefixPath.validate.type = "validate"
;Form Element - email
logon.form.elements.email.type = "text"
logon.form.elements.email.options.required = "true"
logon.form.elements.email.options.label = "Email"
logon.form.elements.email.options.decorators.composite.decorator = "Composite"
logon.form.elements.email.options.validators.strlen.validator = "StringLength"
logon.form.elements.email.options.validators.strlen.options.min="2"
logon.form.elements.email.options.validators.strlen.options.max="50"
;Form Element - Password
logon.form.elements.password.type = "password"
logon.form.elements.password.options.required = "true"
logon.form.elements.password.options.label = "Password"
logon.form.elements.password.options.decorators.composite.decorator = "Composite"
logon.form.elements.password.options.validators.strlen.validator = "StringLength"
logon.form.elements.password.options.validators.strlen.options.min="2"
logon.form.elements.password.options.validators.strlen.options.max="20"
;Form Element - Submit
logon.form.elements.submit.type = "submit"
logon.form.elements.submit.options.label = "Logon"
;Form Display Group 1
logon.form.displaygroups.group1.name = "logon"
logon.form.displaygroups.group1.options.legend = "Please Login to your Account"
logon.form.displaygroups.group1.options.decorators.formelements.decorator = "FormElements"
logon.form.displaygroups.group1.options.decorators.fieldset.decorator = "Fieldset"
logon.form.displaygroups.group1.options.decorators.fieldset.options.style = "width:375px;"
logon.form.displaygroups.group1.elements.email = "email"
logon.form.displaygroups.group1.elements.password = "password"
logon.form.displaygroups.group1.elements.submit = "submit"
And my YAML translation:
production:
logon:
form:
action: /customers/plogin
method: post
id: loginform
elementPrefixPath:
decorator:
prefix: Elite_Decorator_
path: Elite/Decorator/
type: decorator
validate:
prefix: Elite_Validate_
path: Elite/Validate/
type: validate
elements:
email:
type: text
options:
required: true
label: Email
decorators:
composite:
decorator: Composite
validators:
strlen:
validator: StringLength
options:
min: 2
max: 50
password:
type: text
options:
required: true
label: Password
decorators:
composite:
decorator: Composite
validators:
strlen:
validator: StringLength
options:
min: 2
max: 20
submit:
type: submit
options:
label: Logon
displaygroups:
group1:
name: logon
options:
legend: Please login to your account
decorators:
formelements:
decorator: FormElements
fieldset:
decorator: Fieldset
options:
style: width:375px;
elements:
email: email
password: password
submit: submit
The YAML based form only gives me a blank page. Upon investigation, none of the form markup is included in the page that is output. Any help would be greatly appreciated.
Regards,
Troy
I think you should have better indentation in your code:
production:
logon:
form:
action: /customers/plogin
method: post
....