Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By xicath on
Hi people of drupal,
i have some case, i dont know how to solve it, i've been searching for a week
please help me, am really new to drupal7
i have 2 content type : Book and Publisher(example data : PACKT, Oreily, Appress, etc)
i have use entity reference for this 2 content type
how can i know if PACKT already reference in Book?
if it already have reference in Book, it cannot be delete
thanks in advance
Comments
This question belongs either
This question belongs either in Post Installation or Module Development forum, as it is too technical for the General Discussion forum. You can move it.
I am not aware of any module or ready-made code which can disable deletion of a node, depending on some condition. It might exist, though in several years of Drupal site-building I have never seen it. Therefore in order to achieve what you want you need some custom code. You can do this with form validation on the node/%/edit form. You can either create some backend validation in PHP using the Drupal form API (hook_form_alter()) or you can validate the form using javascript in order to disable the 'delete' button if the entity reference is set. In terms of exactly how to write the code, I cannot do that (though you may get help on drupal stackexchange or IRC) - here is a very basic turorial on backend validation http://befused.com/drupal/form-validation
Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors
thanks john, i'm sory if it
thanks john, i'm sory if it wrong room, ok i move this to modul instalation,
as expected its not so so easy
i just want to know if the data already in reference, so it cannot be deleted
by the way, im using pure drupal db schema
is there no modul that at least something like that?
thanks in advance
If you're looking for a
If you're looking for a module, you're still in the wrong section, you want the Post Installation section. Any answers in this section will be purely code related, and if you don't know how to develop Drupal modules, you won't be able to understand the answers.
thats why i am a newbie,
thanks jaypan, thats why i am a newbie, alright i take back my word, just says i looking for a code,
so far i am use devel and search krumo, i created
which table i must join?
its just a simple question hehee
thanks for advance
You'll need to add a
You'll need to add a validation handler to the form (you can do this in hook_form_alter()) and in the validation handler you'll query the database to see if the reference already exists or not. If it does, you call form_set_error() to prevent submission of the form.
okay Mr jaypan,
okay Mr jaypan,
thank u so much for your advice, i will try to figure it out
To do this properly you need
To do this properly using backend route rather than JS validation of the form, you need to learn the Drupal-specific development framework, rather than working directly with the database. The node is an object in php which you can load and query in php, and check whether a field (such as node reference) is set, and the $form_state is a php array which you can modify in php, rather than querying the database directly. The link I gave gives a way into this, and there is more in the very basic and very clear paid ebook by the author of that post.
I won't try to go into this more because I am not a great backend developer myself. Learning this stuff is very much worth doing, and as well as the official node API documentation and Form API documentation there are many written (free tutorials, paid books), video (mainly paid, worth the money), hands-on courses (expensive), and code examples (e.g. Examples module) to help, but takes a few months if you already have good php + mysql skills. If you want a quick solution, best post to Paid Services forum and get someone to do it for you.
Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors
thank you john_b, your link
thank you john_b, your link really helpfull, i will start from there,
i have already start drupal almost 2 month now, learn taxonomy, content_type, themes, multisite, etc
now i stepped in custom module
six month i think the average curve to intermediate level
So there is Paid Services forum in this drupal.org? i dont know that
woow..
Go here https://www.drupal
Go here https://www.drupal.org/forum and search for 'Paid Services'.
Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors