Fields that are imported via config are disabled by default. How to enable them? - drupal

In a custom module for Drupal 8 I'm able to add a new content type with all of its fields, but all of the fields are disabled by default. How do I enable them during install of my module?
Edit To be clear, module fields are not being enabled by default under Manage Form Display. How do I enable (or disable) fields using something like hook install?
Edit 2 Along with enabling fields by default in a newly created content type, installing this module also updates fields on an existing content type (Article) and those fields are also disabled.
Edit 3 disabled meaning they are shown as disabled on the form display for the content type and users cannot see the fields when adding content.
There must be code that I can run via hook_install that enabled fields on a content type?

I'm presuming that by "disabled" you mean that the fields aren't displayed when an instance of your content type is made.
Personally I've been using the UI to set up how each of my fields are displayed through the "Manage Display" page provided for each content type. I drag the fields that I want to enable from the disabled section as you would normally.
When I'm happy with how the fields are arranged I then use the brilliant inbuilt export functionality (think features in Drupal 7 but way better) to generate the .yml config files for my content type.
This process is described brilliantly by this article on the Drupal website. In this case, as it's just the config for which fields that we want to display, it should be as simple as exporting the "Entity View Display" config for the content type to a .yml file. (note that you need to name your yml files correctly, this is explained in the article (and I think that the export module provides the auto-generated name anyway)).
Here is what the export looks like for one of my content types:
Once I've generated the config files that I want to apply to Drupal when the module is enabled it really is as simple as making two directories in the root directory of the module:
"./config/install"
and placing the config files into the install directory.
Now, when the module is first installed Drupal will apply the configuration provided by the files in the /config/install directory.
This process is elaborated upon here: https://www.drupal.org/docs/8/creating-custom-modules/include-default-configuration-in-your-drupal-8-module

When you export a field you have to export too:
"Field declaration" field.field.[entity_type].[bundle].[field_name].yml file. Don't forget to add re-used fields declaration
"Field Storage" field.storage.[entity_type].[field_name].yml file
"Form Display" where you have modified the field configuration. core.entity_form_display.[entity_type].[budle].default.yml
"Manage Display" where you have modified the field configuration. core.entity_view_display.[entity_type].[budle].[view_mode_id].yml files (If you have Default, Teaser, etc)
"Entity", if the entity is new. [entity_type].[type|paragraph_type|vocabulary].[bundle].yml file
I recommend you to use "drush cex/cim" commands to import and export configuration.

I don't know too much about Drupal 8 but when i try to create custom content type to use this article.
https://www.drupal.org/docs/8/api/entity-api/creating-a-custom-content-type-in-drupal-8
Then when i enable our custom module then content type is created successfully and the content type fields are also enabled.
Also i have try to create a node in this content type then the node is successfully created.
So please check this article.
It may be helpful for you.
Thanks,

Related

AEM Metadata Schema Editor Form doesn't show Asset Rating field

I'm creating new fields to customize the Assets Metadata Schema, however, there is a field missing: Asset Rating. Looking into the web I've figured out that is disabled on .jsp configuration file, so, I've enabled that (uncommenting) directly in CRX repository. However, after trying this approach the field keeps missing on the form
Obs.: I don't what means that comment
<!-- CQ-4284633 Disable ratings component in metaschema editor when skyline is enabled -->.
Are you using AEM as a Cloud Service? If so, the Asset Ratings widget is not supported in the schema editor.
From the feature parity section of the AEM Assets Cloud notable changes.

In drupal 7 user access only files assigned to him

Hello I want to user in system have files that only that registered user can open. And there is no other access to it.
Can it be done in Drupal 7 like so: configuration->account settings add new type as file and set it as private? Or there is other better way to achieve that ??
To do it without modules, see this page:
https://www.drupal.org/node/1792780
Or here are a couple of modules:
https://www.drupal.org/project/file_access
https://www.drupal.org/project/private_files_download_permission
Along with making storing the files in a private folder on your server, try the content access module: https://www.drupal.org/project/content_access
It creates a view own permission on a content type that will allow you to grant view permissions on content only for the owner. You would just create a new content type for this type of file and then grant the proper access for that new content type. It also says in the documentation that the module allows for access control not only at the content type level, but also at the node level.

No Custom Tool in resx file properties

I want to change the access modifier of my *.resx file to public. However, the Access Modifier drop down option is disabled.
I read the answer to this question, where it says to change the file's Custom Tool back to the default "ResXFileCodeGenerator". But, in my file properties, there isn't a field for Custom Tool:
How do I get the Custom Tool property?

Drupal6: I need to customize file upload links in node edit form

I am customizing the node/add and node/edit forms of a content type with a form_alter. In my content type, there is a file field that permits to upload files to the content.
What I would like to do is to customize the file box by changing the link to the file that is composed at runtime with Ajax. How can I do it without modifying Drupal core?
Your Private Files directory should not be in the docroot. Hiding it with a .htaccess rule will not work, as you point out in a comment.
Say you have Drupal in /var/www/sites/example.com/, then you should not store your private files under that directory; /var/www/sites/example.com/sites/default/private/files/ is just plain wrong.
You should, instead store the files where apache will not serve them, but can read them. E.g. in /var/www/files/example.com/. Then change the setting in Drupal to use that absolute path.
If you are running a large(r) site, you will probably want to store your files on a dedicated mount (drive, NFS etc.), say /media/nfs-example-com/.
Try Filefield Paths:
The FileField Paths module extends the default functionality of Drupals core Upload module, the FileField module and many other File Upload modules by adding the ability to use node tokens in destination paths and filenames.
http://drupal.org/project/filefield_paths

How to store Blobs in Drupal?

I want to store PDF and Image files in Drupal. By default Drupal seems to store binary/uploaded files into the filesystem. I want to to be able to store files so that - I can have workflows, metadata, IP information and URL aliases?
Update, am still stuck at how to create URL aliases for files on the file system. Drupal only seems to allow creating URL aliases to node content.
The simplest solution for Drupal is to use the Upload module, which is in core. The upload module allows you attach files to nodes. As you note, they are stored in the filesystem.
If you want to get more complex, you can build your own content types through the web interface by using the CCK family of modules (such as the filefield module or the imagefield module). Your files are still stored on the filesystem.
You could use CCK to create the metadata field you want.
You could use the workflow or rules modules to implement workflow.
IP information is recorded automatically by Drupal's logging module (either the database logging module, which logs to the database, or the syslog module, which logs to syslog).
URL aliases for nodes are available in core Drupal by enabling the path module (or download the pathauto module for automatic creation of aliases).
I tried Drupal's Upload module, FileField as well as uploading files using FCKEditor - I prefer the last one - it is closer to my specific scenario.
Creating an alias to the file will likely require some custom code.
It's not possible to simply create an alias using the Administer > Site building > URL aliases screen. I tried inserting a record with
insert into url_alias (src, dst) values ('sites/default/files/ChipotleArt.JPG', 'here-is-the-file.jpg');
That still didn't work. So, you will really likely need to write some custom code.

Resources