When users create a new widget instance, WordPress automatically manages configuration options for that element using an array variable. It also calls the widget class' form method, if present, to render the widget instance's options in a configuration panel.
The first few lines of code in the form method verify that the instance array contains proper values that specify whether the widget should be displayed, the number of book reviews to be shown, and the title that should be displayed at the beginning of the widget. If any of these options are missing, we use the PHP ternary conditional operator (?:) to assign default values to the render_widget, nb_book_reviews, and widget_title functions. This operator expects three expressions, ordered as follows: (expr1)?(expr2):(expr3). It will then return expr2 if expr1 is true and expr3 if it's false.
With these variables in place, the rest of the form method's code uses a mix of HTML and PHP code to render the configuration fields that are shown in the widget editor. The get_field_id and get_field_name methods, seen throughout this code, are used to generate unique identifiers that will help WordPress to store data separately for all widget instances.
As can be seen in this recipe, the widget class is able to automatically process and save widget configuration parameters. However, it should be noted that allowing WordPress to handle this task by itself means that no validation will be performed on the data entered. This could cause problems if a user enters text instead of the number of reviews to be displayed. The next recipe shows how to handle data validation.